local extension = Package:new("hxdingzhi")
extension.extensionName = "huixiang"

Fk:loadTranslationTable{
  ["hxdingzhi"] = "回想·定制",
  ["huixiangqy"] = "回想·定制",
}

local U = require "packages/utility/utility"
--魏势力
local huixiangqy__jiecaoang =  General:new(extension, "huixiangqy__jiecaoang","wei",4) --1界曹昂
local huixiangqy__mouguojia = General:new(extension, "huixiangqy__mouguojia", "wei", 3) --2谋郭嘉
local huixiangqy__mousimayi = General:new(extension, "huixiangqy__mousimayi", "wei", 3) --3谋司马懿
local huixiangqy__mouxuchu = General:new(extension, "huixiangqy__mouxuchu","wei",4) --4谋许褚
local huixiangqy__moudianwei = General:new(extension, "huixiangqy__moudianwei", "wei", 4) --5谋典韦
local huixiangqy__moucaochong =  General:new(extension, "huixiangqy__moucaochong","wei",3,4) --6谋曹冲
--local huixiangqy__moucaopi = General:new(extension, "huixiangqy__moucaopi", "wei", 3) --7谋曹丕
--local huixiangqy__mouhepi = General:new(extension, "huixiangqy__hecaopi", "wei", 4) --8合曹丕
local huixiangqy__xingcaochun = General:new(extension, "huixiangqy__xingcaochun", "wei", 4) --9醒曹纯
--local huixiangqy__xingcaozhang = General:new(extension, "huixiangqy__xingcaozhang", "wei", 4) --10星曹彰

--蜀势力
local huixiangqy__spzhugeliang = General:new(extension, "huixiangqy__spzhugeliang","shu",3) --11SP诸葛亮
local huixiangqy__jiemaliang =  General:new(extension, "huixiangqy__jiemaliang","shu",3) --12界马良
local huixiangqy__moumadai = General:new(extension, "huixiangqy__moumadai", "shu", 4) --13谋马岱
--local huixiangqy__mouliushan = General:new(extension, "huixiangqy__mouliushan", "shu", 3,4) --14谋刘禅
--local huixiangqy__liuchen = General:new(extension, "huixiangqy__liuchen", "shu", 3) --15刘谌

--吴势力
local huixiangqy__spzhouyu = General:new(extension, "huixiangqy__spzhouyu","wu",4) --17SP周瑜
local huixiangqy__jietaishici = General:new(extension, "huixiangqy__jietaishici", "wu", 4) --18界太史慈
--local huixiangqy__mousunquan = General:new(extension, "huixiangqy__mousunquan", "wu", 4) --19谋孙权
local huixiangqy__mouganning = General:new(extension, "huixiangqy__mouganning","wu",4) --20谋甘宁
local huixiangqy__shisunquan = General:new(extension, "huixiangqy__shisunquan", "wu", 4) --21势孙权
local huixiangqy__daoxusheng = General:new(extension, "huixiangqy__daoxusheng", "wu", 4) --22刀徐盛
 
--群势力
local huixiangqy__spsimayi = General:new(extension, "huixiangqy__spsimayi", "qun", 1) --23SP司马懿
huixiangqy__spsimayi.shield = 2
local huixiangqy__xingliubei = General:new(extension, "huixiangqy__xingliubei", "qun", 4) --24星刘备
--local huixiangqy__xingzhaoyun = General:new(extension, "huixiangqy__xingzhaoyun", "qun", 3) --25星赵云
--local huixiangqy__xingmachao = General:new(extension, "huixiangqy__xingmachao", "qun", 3) --26星马超
local huixiangqy__shimachao = General:new(extension, "huixiangqy__shimachao", "qun", 3) --27势马超
huixiangqy__shimachao.shield = 1
--local huixiangqy__shilvbu = General:new(extension, "huixiangqy__shilvbu", "qun", 4) --28势吕布
local huixiangqy__jiequyi = General:new(extension, "huixiangqy__jiequyi", "qun", 4) --29界麴义
local huixiangqy__maoliuyan = General:new(extension, "huixiangqy__maoliuyan", "qun", 3) --30矛刘焉
local huixiangqy__hewenyang = General:new(extension, "huixiangqy__hewenyang", "qun", 4) --31合文鸯
local huixiangqy__nujvshou = General:new(extension, "huixiangqy__nujvshou", "qun", 2,3) --32弩沮授
huixiangqy__nujvshou.shield = 3

--晋势力
local huixiangqy__bianzhouchu = General:new(extension, "huixiangqy__bianzhouchu", "jin", 3) --33变周处

--神势力
local huixiangqy__xingzuoci =  General:new(extension, "huixiangqy__xingzuoci","god",3) --34星左慈
--local huixiangqy__shenyuanshao = General:new(extension, "huixiangqy__shenyuanshao", "god", 4) --35神袁绍
local huixiangqy__shenxusheng = General:new(extension, "huixiangqy__shenxusheng", "god", 4) --36神徐盛


Fk:loadTranslationTable{
  ["huixiangqy__xingcaochun"] = "醒曹纯",
  ["designer:huixiangqy__xingcaochun"] = "非电竞恐龙",
  ["huixiangqy__mousunquan"] = "谋孙权",
  ["designer:huixiangqy__mousunquan"] = "非电竞恐龙",
  ["huixiangqy__daoxusheng"] = "刀徐盛",
  ["designer:huixiangqy__daoxusheng"] = "非电竞恐龙",
  ["huixiangqy__jiequyi"] = "界麴义",
  ["designer:huixiangqy__jiequyi"] = "非电竞恐龙",
  ["huixiangqy__maoliuyan"] = "矛刘焉",
  ["designer:huixiangqy__maoliuyan"] = "非电竞恐龙",
  ["huixiangqy__hewenyang"] = "合文鸯",
  ["designer:huixiangqy__hewenyang"] = "非电竞恐龙",
  ["huixiangqy__bianzhouchu"] = "变周处",
  ["designer:huixiangqy__bianzhouchu"] = "非电竞恐龙",
}



  Fk:loadTranslationTable{
    ["huixiangqy__moumadai"] = "谋马岱",
    ["designer:huixiangqy__moumadai"] = "恐龙王乐园",
    ["hx__qianxi"] = "潜袭",
    ["#hx__qianxi_attack"] = "潜袭",
    [":hx__qianxi"] = "准备阶段，你可以摸至多3张牌并弃置一张牌，然后你此阶段出杀次数+x(x为2减你摸的牌数且若x为负数则你本回合不能出杀)且此回合你可将一张【杀】当任意基本牌使用。若如此做，你选择一名角色，然后本回合该角色不能使用或打出与你以此法弃置的牌颜色相同的手牌。每当你使用【杀】对目标角色造成伤害时，你可以选择防止此伤害，然后其减一点体力上限。",
    ["@hx__qianxi_chusha"] = "出杀次数+",
    ["@hx__qianxi_jingsha"] = "不能出杀",
    ["@qianxi-turn"] = "潜袭",
    ["#hx__qianxi-choices"] = "是否发动潜袭？",
    ["#hx__qianxi-choice"] = "请选择要摸的牌数",
    ["hx__qianxi0"] = "0张",
    ["hx__qianxi1"] = "1张",
    ["hx__qianxi2"] = "2张",
    ["hx__qianxi3"] = "3张",
    ["#qianxi-discard"] = "请弃置一张牌",
    ["#hx__qianxi-choose"] = "潜袭：你选择一名角色，然后本回合该角色不能使用或打出与你以此法弃置的牌颜色相同的手牌。",
    ["madai__masu"] = "马术",
    [":madai__masu"] = "锁定技，你计算与其他角色距离减一，其他角色计算与你距离加一。",
    ["$hx__qianxi1"] = "叛夫小儿，快快授首！",
    ["$hx__qianxi2"] = "擒贼先擒王，打蛇打七寸！",
    ["$hx__qianxi_mod1"] = "叛夫小儿，快快授首！",
    ["$hx__qianxi_mod2"] = "擒贼先擒王，打蛇打七寸！",
    ["~huixiangqy__moumadai"] = "反骨贼已除，丞相放心。",
  }

  local hx__qianxi = fk.CreateTriggerSkill {
    name = "hx__qianxi",
    anim_type = "control",
    events = {fk.EventPhaseStart},
    can_trigger = function(self, event, target, player, data)
        return target == player and player:hasSkill(self) and player.phase == Player.Start
    end,
    on_cost = function(self, event, target, player, data)
      local room = player.room
      if room:askForSkillInvoke(player, self.name, data, "#hx__qianxi-choices") then
        local choices = {"hx__qianxi0","hx__qianxi1","hx__qianxi2", "hx__qianxi3"}
        local choice = player.room:askForChoice(player, choices, self.name, "#hx__qianxi-choice")
        if choice then
          self.cost_data = choice
          return true
        end
        return false
      end
    end,
    on_use = function(self, event, target, player, data)
      local room = player.room
      if not player.dead then
        room:handleAddLoseSkills(player, "hx__qianxi_mod", nil, true, false)
        room.logic:getCurrentEvent():findParent(GameEvent.Turn):addCleaner(function()
          room:handleAddLoseSkills(player, "-hx__qianxi_mod", nil, true, false)
        end)
      end
      if self.cost_data == "hx__qianxi0" then
        player.room:addPlayerMark(player, "@hx__qianxi_chusha", 2)
        local cardDiscarded = room:askForDiscard(player, 1, 1, true, self.name, false, ".", "#qianxi-discard")
        if player.dead then return end
        if not cardDiscarded or #cardDiscarded == 0 then return end
        local color = Fk:getCardById(cardDiscarded[1]):getColorString()
        local targets = table.map(room:getOtherPlayers(player, false), Util.IdMapper)
        if #targets == 0 then return end
        local targetId = room:askForChoosePlayers(player, targets, 1, 1, "#hx__qianxi-choose:::" .. color, self.name, false)[1]
        if not targetId then return end
        room:setPlayerMark(room:getPlayerById(targetId), "@qianxi-turn", color)
        room:setPlayerMark(player, "_hx__qianxi_target-turn", targetId)
      elseif self.cost_data == "hx__qianxi1" then
        player:drawCards(1, self.name)
        player.room:addPlayerMark(player, "@hx__qianxi_chusha", 1)
        local cardDiscarded = room:askForDiscard(player, 1, 1, true, self.name, false, ".", "#qianxi-discard")
        if player.dead then return end
        if not cardDiscarded or #cardDiscarded == 0 then return end
        local color = Fk:getCardById(cardDiscarded[1]):getColorString()
        local targets = table.map(room:getOtherPlayers(player, false), Util.IdMapper)
        if #targets == 0 then return end
        local targetId = room:askForChoosePlayers(player, targets, 1, 1, "#hx__qianxi-choose:::" .. color, self.name, false)[1]
        if not targetId then return end
        room:setPlayerMark(room:getPlayerById(targetId), "@qianxi-turn", color)
        room:setPlayerMark(player, "_hx__qianxi_target-turn", targetId)
      elseif self.cost_data == "hx__qianxi2" then
        player:drawCards(2, self.name)
        local cardDiscarded = room:askForDiscard(player, 1, 1, true, self.name, false, ".", "#qianxi-discard")
        if player.dead then return end
        if not cardDiscarded or #cardDiscarded == 0 then return end
        local color = Fk:getCardById(cardDiscarded[1]):getColorString()
        local targets = table.map(room:getOtherPlayers(player, false), Util.IdMapper)
        if #targets == 0 then return end
        local targetId = room:askForChoosePlayers(player, targets, 1, 1, "#hx__qianxi-choose:::" .. color, self.name, false)[1]
        if not targetId then return end
        room:setPlayerMark(room:getPlayerById(targetId), "@qianxi-turn", color)
        room:setPlayerMark(player, "_hx__qianxi_target-turn", targetId)
      elseif self.cost_data == "hx__qianxi3" then
        player:drawCards(3, self.name)
        player.room:addPlayerMark(player, "@hx__qianxi_jingsha", 1)
        local cardDiscarded = room:askForDiscard(player, 1, 1, true, self.name, false, ".", "#qianxi-discard")
        if player.dead then return end
        if not cardDiscarded or #cardDiscarded == 0 then return end
        local color = Fk:getCardById(cardDiscarded[1]):getColorString()
        local targets = table.map(room:getOtherPlayers(player, false), Util.IdMapper)
        if #targets == 0 then return end

        local targetId = room:askForChoosePlayers(player, targets, 1, 1, "#hx__qianxi-choose:::" .. color, self.name, false)[1]
        if not targetId then return end
        room:setPlayerMark(room:getPlayerById(targetId), "@qianxi-turn", color)
        room:setPlayerMark(player, "_hx__qianxi_target-turn", targetId)
      end
    end,
    refresh_events = {fk.Damage, fk.AfterTurnEnd, fk.EventPhaseStart},
      can_refresh = function(self, event, target, player, data)
          if target ~= player then return end
          if event == fk.Damage then
              return not data.to.dead and player:getMark("_hx__qianxi_target-turn") == data.to.id
                  and data.card and data.card.trueName == "slash" and player.phase ~= Player.NotActive
          elseif event == fk.AfterTurnEnd then
              return player:getMark("@qianxi-turn") ~= 0
          else
              return player.phase == Player.Finish and player:getMark("_hx__qianxi_done-turn") > 0
          end
      end,
      on_refresh = function(self, event, target, player, data)
          local room = player.room
          if event == fk.Damage then
              room:setPlayerMark(player, "_hx__qianxi_done-turn", 1)
          elseif event == fk.AfterTurnEnd then
              room:setPlayerMark(player, "@qianxi-turn", 0)
          else
              local p = room:getPlayerById(player:getMark("_hx__qianxi_target-turn"))
              local color = p:getMark("@qianxi-turn")
              room:setPlayerMark(p, "@qianxi-turn", color == "red" and "black" or "red")
          end
      end,
    
}

local hx__qianxi_prohibit = fk.CreateProhibitSkill {
  name = "#hx__qianxi_prohibit",
  prohibit_use = function(self, player, card)
    if player:getMark("@hx__qianxi") ~= 0 and card:getColorString() == player:getMark("@hx__qianxi") then return true end
    if player:getMark("@qianxi-turn") ~= 0 and card:getColorString() == player:getMark("@qianxi-turn") then return true end
    if player:getMark("@hx__qianxi_jingsha") > 0 and card.trueName == "slash"then return true end
  end,
  prohibit_response = function(self, player, card)
    if player:getMark("@hx__qianxi") ~= 0 and card:getColorString() == player:getMark("@hx__qianxi") then return true end
    if player:getMark("@qianxi-turn") ~= 0 and card:getColorString() == player:getMark("@qianxi-turn") then return true end
  end,
}

local hx__qianxi_chusha = fk.CreateTargetModSkill{
  name = "#hx__qianxi_chusha",
  residue_func = function(self, player, skill, scope, card)
    if player:hasSkill("hx__qianxi") and skill.trueName == "slash_skill" and scope == Player.HistoryPhase then
      return player:getMark("@hx__qianxi_chusha")
    end
    return 0
  end,
}

local hx__qianxi_remove = fk.CreateTriggerSkill{
  name = "#hx__qianxi_remove",
  mute = true,
  frequency = Skill.Compulsory,
  events = {fk.EventPhaseEnd},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self.name) and player.phase == Player.Finish then
     return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:setPlayerMark(player, "@hx__qianxi_chusha", 0)
    room:setPlayerMark(player, "@hx__qianxi_jingsha", 0)
  end,
}

local hx__qianxi_attack = fk.CreateTriggerSkill{
    name = "#hx__qianxi_attack",
    anim_type = "offensive",
    events = {fk.DamageCaused},
    can_trigger = function(self, event, target, player, data)
      return target and target == player and player:hasSkill(self) and data.to ~= player and not data.to.dead and
        data.card and data.card.trueName == "slash"
    end,
    on_cost = function(self, event, target, player, data)
      local invoked = player.room:askForSkillInvoke(player, self.name, "#hx__qianxi-invoke::"..data.to.id)
      if invoked then
        self.cost_data = data.to.id
        return true
      end
      return false
    end,
    on_use = function(self, event, target, player, data)
      local room = player.room
      player:broadcastSkillInvoke("hx__qianxi")
      data.damage = 0
      room:changeMaxHp(data.to, -1)
    end,
}

local hx__qianxi_mod = fk.CreateViewAsSkill{
  name = "hx__qianxi_mod",
  anim_type = "offensive",
  prompt = "#hx__qianxi_mod",
  pattern = ".|.|.|.|.|basic",
  interaction = function(self)
    local all_names = U.getAllCardNames("b")
    local names = U.getViewAsCardNames(Self, "hx__qianxi_mod", all_names)
    if #names > 0 then
      return UI.ComboBox { choices = names, all_choices = all_names }
    end
  end,
  handly_pile = true,
  card_filter = function(self, to_select, selected)
    return #selected ==0 and Fk:getCardById(to_select).trueName == "slash"
  end,
  view_as = function(self, cards)
    local choice = self.interaction.data
    if  #cards ~= 1 then return end
    local card = Fk:cloneCard(choice)
    card:addSubcards(cards)
    card.skillName = self.name
    return card
  end,
  enabled_at_response = function(self, player, response)
    return not response
  end,
}

Fk:loadTranslationTable{
   ["hx__qianxi_mod"] = "潜袭",
   ["#hx__qianxi_mod"] = "潜袭：你可以将一张【杀】当任意基本牌使用。",
   [":hx__qianxi_mod"] = "你可以将一张【杀】当任意基本牌使用。",
}


huixiangqy__moumadai:addSkill(hx__qianxi)
huixiangqy__moumadai:addRelatedSkill(hx__qianxi_mod)
hx__qianxi:addRelatedSkill(hx__qianxi_chusha)
hx__qianxi:addRelatedSkill(hx__qianxi_remove)
hx__qianxi:addRelatedSkill(hx__qianxi_prohibit)
hx__qianxi:addRelatedSkill(hx__qianxi_attack)


local madai__masu = fk.CreateDistanceSkill{
  name = "madai__masu",
  frequency = Skill.Compulsory,
  correct_func = function(self, from, to)
    if from:hasSkill(self) then
      return -1
    end
    if to:hasSkill(self) then
      return 1
    end
  end,
}

huixiangqy__moumadai:addSkill(madai__masu)




Fk:loadTranslationTable{
  ["huixiangqy__mouguojia"] = "谋郭嘉",
  ["designer:huixiangqy__mouguojia"] = "恐龙王乐园",
  ["hx__yiji"] = "遗计",
  [":hx__yiji"] = "当你受到1点伤害后，你可以摸一张牌，然后可以将至多两张牌交给其他角色。",
  ["hx__miaoce"] = "妙策",
  [":hx__miaoce"] = "当你发动【遗计】后，若你的手牌颜色相同或类型相同，你可以进行一次判定，若判定牌颜色为红/黑，你选择一名角色对其造成一点伤害/依次弃置其两张牌。",
  ["hx__tiandu"] = "天妒",
  [":hx__tiandu"] = "出牌阶段开始时，你可以视为受到一点无来源伤害（每两轮限一次）；当你的判定牌生效后，你可以获得之。",
  ["$hx__tiandu1"] = "天降大任于吾，吾必成之！",
  ["$hx__tiandu2"] = "既得天智，又岂能再乞天佑？",
  ["$hx__yiji1"] = "定此遗计，以全此生。",
  ["$hx__yiji2"] = "沥血铸策，锻此身以助明公！",
  ["$hx__miaoce1"] = "愿倾吾毕生之才，以圆主公之志。",
  ["$hx__miaoce2"] = "兵强尚且思谋，势弱更应多算。",
  ["~huixiangqy__mouguojia"] = "执鞭扫南之日，嘉再贺明公于九泉……",
  ["$huixiangqy__mouguojia_win_audio"] = "天命已成，嘉无负明公之恩！",
}
local huixiangqy__mouguojiawin = fk.CreateActiveSkill{ name = "huixiangqy__mouguojia_win_audio" }
huixiangqy__mouguojiawin.package = extension
Fk:addSkill(huixiangqy__mouguojiawin)

local hx__yiji = fk.CreateTriggerSkill{
  name = "hx__yiji",
  anim_type = "masochism",
  events = {fk.Damaged},
  on_trigger = function(self, event, target, player, data)
    self.cancel_cost = false
    for _ = 1, data.damage do
      if player.dead or self.cancel_cost then return end
      self:doCost(event, target, player, data)
    end
  end,
  on_cost = function(self, event, target, player, data)
    if player.room:askForSkillInvoke(target, self.name, data) then return true end
    self.cancel_cost = true
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:drawCards(1, self.name)
    if player.dead or player:isKongcheng() then return end
    player.room:askForYiji (player, player:getCardIds("h"), room:getOtherPlayers(player), self.name, 0, 2)
  end
}
huixiangqy__mouguojia:addSkill(hx__yiji)

local hx__miaoce = fk.CreateTriggerSkill{
  name = "hx__miaoce",
  anim_type = "judgement",
  events = {fk.DamageInflicted,fk.CardUsing,fk.AskForRetrial,fk.AfterSkillEffect},
  can_trigger = function(self, event, target, player, data)
    if target ~= player or not player:hasSkill(self) or data.name ~= "hx__yiji" then return end
    local room = player.room
    local cards = player:getCardIds("h")
    if table.every(cards, function(id) return #cards == 0 or Fk:getCardById(id).color == Fk:getCardById(cards[1]).color end)
      or table.every(cards, function(id) return #cards == 0 or Fk:getCardById(id).type == Fk:getCardById(cards[1]).type end) then
      return true
    end
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askForSkillInvoke(player, self.name, data, "#hx__miaoce-invoke")
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:notifySkillInvoked(player, self.name)
    local judge = {
      who = player,
      reason = self.name,
      pattern = ".|.|.",
    }
    room:judge(judge)
    if judge.card.color == Card.Red then
      local targets = room:askForChoosePlayers(player, table.map(room.alive_players, Util.IdMapper), 1, 1, "#hx__miaoce-ask-red", self.name, true)
      if #targets > 0 then
        room:damage({
          from = player,
          to = room:getPlayerById(targets[1]),
          damage = 1,
          skillName = self.name,
        })
      end
    elseif judge.card.color == Card.Black then
      local targets = room:askForChoosePlayers(player, table.map(room.alive_players, Util.IdMapper), 1, 1, "#hx__miaoce-ask-black", self.name, true)
      if room:getPlayerById(targets[1]):isNude() then return end
      if #targets > 0 then
        local id1 = room:askForCardChosen(player, room:getPlayerById(targets[1]), "he", self.name, "#hx__miaoce-discard1::" )
        room:throwCard({id1}, self.name, room:getPlayerById(targets[1]), player)
        if room:getPlayerById(targets[1]):isNude() then return end
        local id2 = room:askForCardChosen(player, room:getPlayerById(targets[1]), "he", self.name, "#hx__miaoce-discard2::" )
        room:throwCard({id2}, self.name, room:getPlayerById(targets[1]), player)
      end
    end
  end,
}

huixiangqy__mouguojia:addSkill(hx__miaoce)

Fk:loadTranslationTable{
  ["#hx__miaoce-invoke"] = "是否发动妙策进行一次判定？",
  ["#hx__miaoce-ask-red"] = "妙策：选择一名角色对其造成一点伤害",
  ["#hx__miaoce-ask-black"] = "妙策：选择一名角色依次弃置其两张牌",
  ["#hx__miaoce-discard1"] = "妙策：请选择要弃置的第一张牌",
  ["#hx__miaoce-discard2"] = "妙策：请选择要弃置的第二张牌",
  ["#hx__tiandu_damage"] = "天妒",
  ["#hx__tiandu_effect"] = "获得天妒发动次数",
  ["@hx__tiandu"] = "天妒发动次数",
}


local hx__tiandu = fk.CreateTriggerSkill{
  name = "hx__tiandu",
  anim_type = "drawcard",
  events = {fk.FinishJudge},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player.room:getCardArea(data.card) == Card.Processing
  end,
  on_use = function(self, event, target, player, data)
    player.room:obtainCard(player.id, data.card, true, fk.ReasonJustMove)
  end,
}
local hx__tiandu_damage = fk.CreateTriggerSkill{
  name = "#hx__tiandu_damage",
  anim_type = "damage",
  events = {fk.EventPhaseStart},
  can_trigger = function (self, event, target, player, data)
    return player:hasSkill(self) and target and target == player and player.phase == Player.Play 
    and player:getMark("@hx__tiandu") == 1
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    player:broadcastSkillInvoke("hx__tiandu")
    room:damage{
      from = nil,
      to = player,
      damage = 1,
      skillName = self.name,
      isVirtualDMG = true,
    }
  end,
}
local hx__tiandu_remove = fk.CreateTriggerSkill{
  name = "#hx__tiandu_remove",
  mute = true,
  events = {fk.RoundEnd,fk.AfterSkillEffect},
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    local roundCount = player.room:getTag("RoundCount")
    if event == fk.RoundEnd then
      return target == player and player:hasSkill(self) and (roundCount % 2 == 0)
    else
      return target == player and player:hasSkill(self) and  data.name == "#hx__tiandu_damage"
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:setPlayerMark(player, "@hx__tiandu", 0)
  end,
}
local hx__tiandu_effect = fk.CreateTriggerSkill{
  name = "#hx__tiandu_effect",
  mute = true,
  events = {fk.RoundStart},
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    local roundCount = player.room:getTag("RoundCount")
    return player:hasSkill(self) and (roundCount % 2 == 1)
  end,
  on_use = function(self, event, target, player, data)
    player.room:addPlayerMark(player, "@hx__tiandu", 1)
  end,
}

huixiangqy__mouguojia:addSkill(hx__tiandu)
hx__tiandu:addRelatedSkill(hx__tiandu_remove)
hx__tiandu:addRelatedSkill(hx__tiandu_damage)
hx__tiandu:addRelatedSkill(hx__tiandu_effect)


Fk:loadTranslationTable{
  ["huixiangqy__xingliubei"] = "星刘备",
  ["designer:huixiangqy__xingliubei"] = "恐龙王乐园",
  ["hx__youli"] = "游历",
  [":hx__youli"] = "出牌阶段限一次，你可以选择一名与你距离为1的角色对其造成1点伤害。",
  ["#hx__youli-prompt"] = "游历：你可以选择一名与你距离为1的角色对其造成1点伤害。"..
  "<br/><font color='red'><b>注</b>：请勿选择距离为1以外的角色。</font>",
  ["#hx__youli-target"] = "请选择你想对其造成伤害的角色",
  ["hx__kuangfu"] = "匡扶",
  [":hx__kuangfu"] = "锁定技，当你受到1点伤害时，你令伤害来源选择一项：1.交给你一张牌然后随机弃置一张牌；2.失去两点体力对你造成一点伤害。",
  ["#hx__kuangfu-ask"] = "匡扶：请选择一项",
  ["#hx__kuangfu-choose_card"] = "匡扶：请交给%src一张牌且你将随机弃置一张牌，否则你失去两点体力并对%src造成一点伤害",
  ["hx__kuangfu_losehp"] = "失去两点体力，对星刘备造成一点伤害",  
  ["#hx__kuangfu-discard"] = "匡扶：选择一张手牌弃置",
  ["#hx__kuangfu-give"] = "匡扶：交给其一张手牌",
  ["hx__caoxie"] = "草鞋",
  [":hx__caoxie"] = "锁定技，你计算与其他角色距离-1，其他角色计算与你距离+1。准备阶段你摸一张牌。",
  ["$hx__caoxie1"] = "勿以恶小而为之，勿以善小而不为！",
  ["$hx__caoxie2"] = "民若得安，则天下安矣！",
  ["$hx__kuangfu1"] = "备宁愿一死，只求百姓得安！",
  ["$hx__kuangfu2"] = "大汉倾危，无人扶之乎？",
  ["$hx__youli1"] = "仁者，自当胸怀天下！",
  ["$hx__youli2"] = "物尽其用，方可人尽其才！",
  ["~huixiangqy__xingliubei"] = "楼桑羽葆，黄粱一梦……",
  ["$huixiangqy__xingliubei_win_audio"] = "鲲鹏之志，志在天下苍生！",
}
local huixiangqy__xingliubeiwin = fk.CreateActiveSkill{ name = "huixiangqy__xingliubei_win_audio" }
huixiangqy__xingliubeiwin.package = extension
Fk:addSkill(huixiangqy__xingliubeiwin)

local hx__youli = fk.CreateActiveSkill {
  name = "hx__youli",
  anim_type = "offensive",
  card_num = 0,
  target_num = 1,
  prompt = "#hx__youli-prompt",
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  target_filter = function(self, to_select, selected, effect)
    local target = Fk:currentRoom():getPlayerById(to_select)
    return #selected == 0
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local to = room:getPlayerById(effect.tos[1])
    if to and player:distanceTo(to) == 1 then
      room:damage({
        from = player,
        to = to,
        damage = 1,
        skillName = self.name,
      })
    end
  end,
}



local hx__kuangfu = fk.CreateTriggerSkill {
  name = "hx__kuangfu",
  anim_type = "special",
  frequency = Skill.Compulsory,
  events = { fk.HpRecover, fk.Damaged },
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and data.from
  end,
  on_trigger = function(self, event, target, player, data)
    self.cancel_cost = false
    for i = 1, data.damage do
      if self.cancel_cost or not player:hasSkill(self) then break end
      self:doCost(event, target, player, data)
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local choice_card = room:askForCard(data.from, 1, 1, true, self.name, true, ".|.|.",
      "#hx__kuangfu-choose_card:" .. player.id)
    if #choice_card > 0 then
      room:obtainCard(player, choice_card, true, fk.ReasonGive, player.id, self.name)
      local cards = data.from:getCardIds("he")
      local card = cards[math.random(1, #cards)]
      room:throwCard({card}, self.name, data.from, player)
    else
      room:loseHp(data.from, 2, self.name)
        room:damage({
          from = data.from,
          to = player,
          damage = 1,
          skillName = self.name,
        })
    end
  end,
}
local hx__caoxie = fk.CreateTriggerSkill {
  name = "hx__caoxie",
  events = {fk.TurnStart},
  anim_type = "control",
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self)
  end,
  on_use = function(self, event, target, player, data)
    if event == fk.TurnStart then
      player:drawCards(1, self.name)
    end
  end,
}

local hx__caoxie_distance = fk.CreateDistanceSkill {
  name = "#hx__caoxie_distance",
  frequency = Skill.Compulsory,
  correct_func = function(self, from, to)
    if from:hasSkill(self) then
      return -1
    end
    if to:hasSkill(self) then
      return 1
    end
  end,
}
huixiangqy__xingliubei:addSkill(hx__youli)
huixiangqy__xingliubei:addSkill(hx__kuangfu)
huixiangqy__xingliubei:addSkill(hx__caoxie)
hx__caoxie:addRelatedSkill(hx__caoxie_distance)



Fk:loadTranslationTable{
  ["huixiangqy__spsimayi"] = "SP司马懿",
  ["designer:huixiangqy__spsimayi"] = "恐龙王乐园",
  ["hx__taohui"] = "韬晦",
  [":hx__taohui"] = "准备阶段开始时或你受到伤害时，你可以重铸X张牌（X为你的体力上限）并可以视为对一名其他角色使用一张【决斗】。若重铸的牌中包括：1.锦囊牌，你摸一张你选择的类型的牌；2.黑色牌，该【决斗】的目标角色无法使用红色牌响应；3.红色牌，你摸一张牌并增加一点体力上限。4.装备牌，你增加等量手牌上限。",
  ["#hx__taohui-choose_cards"] = "韬晦：你可以重铸至多X张牌（X为你的体力上限）并可以视为对一名其他角色使用一张【决斗】。",
  ["#hx__taohui-invoke"] = "请选择你想对其使用【决斗】的角色",
  ["@hx__taohui-mark"] = "不能使用红色牌",
  ["hx__zhabing"] = "诈病",
  ["#hx__zhabing2"] = "诈病",
  ["#hx__zhabing_effect"] = "诈病",
  ["hx__taohui_b"] = "摸一张基本牌",
  ["hx__taohui_t"] = "摸一张锦囊牌",
  ["hx__taohui_e"] = "摸一张装备牌",
  [":hx__zhabing"] = "锁定技，你的手牌上限+3；你的回合结束时，若本轮你没有造成过伤害，则你选择一项：1.回复一点体力；2.你获得效果：每轮开始时令你造成的伤害+1直到你造成伤害（该效果可叠加）。",
  ["@hx__zhabing_damage"] = "造成的伤害+",
  ["@hx__taohui-card"] = "手牌上限+",
  ["@@hx__zhabing_candamage"] = "获得加伤",
  ["$hx__taohui1"] = "无为得喜，无为失忧。",
  ["$hx__taohui2"] = "有取必有舍，有禁必有宽。",
  ["$hx__zhabing1"] = "君寒难受雪，路冻莫远行！",
  ["$hx__zhabing2"] = "万象机变，皆系我一掌之中。",
  ["~huixiangqy__spsimayi"] = "筹谋半生事，逢日俱化空……",
}

local hx__taohui = fk.CreateTriggerSkill {
  name = "hx__taohui",
  anim_type = "special",
  events = { fk.EventPhaseStart, fk.DamageInflicted,fk.DamageFinished},
  can_trigger = function(self, event, target, player, data)
    if event == fk.EventPhaseStart and player:hasSkill(self) then
      return player.phase == Player.Start
    elseif event == fk.DamageInflicted and player:hasSkill(self) and target == player then
      return data.from
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local x = player.maxHp
    local draw = 0
    local equip = 0
    local hasRedCard = false
    local hasBlackCard = false
    if #player:getCardIds("he") > 0 then
        local cards = room:askForCardsChosen(player, player, 1, x, "he", self.name, "#hx__taohui-choose_cards")
        if #cards > 0 then
            room:recastCard(cards, player, self.name)
            for _, id in ipairs(cards) do
                local card = Fk:getCardById(id)
                if Fk:getCardById(id).type == Card.TypeTrick then
                  draw = draw + 1
                end
                if Fk:getCardById(id).type == Card.TypeEquip then
                  equip = equip + 1
                end
                if card.color == Card.Red then
                  hasRedCard = true
                end
                if card.color == Card.Black then
                  hasBlackCard = true
                end
            end
            if draw > 0 then
              local choice11 = room:askForChoice(player, {"hx__taohui_b","hx__taohui_t","hx__taohui_e"},self.name)
              if choice11 == "hx__taohui_b" then
                local cards = player.room:getCardsFromPileByRule(".|.|.|.|.|basic")
                if #cards > 0 then
                  room:obtainCard(player, cards[1], false, fk.ReasonDraw, player.id, self.name)
                end
              elseif choice11 == "hx__taohui_t" then
                local cards = player.room:getCardsFromPileByRule(".|.|.|.|.|trick")
                if #cards > 0 then
                  room:obtainCard(player, cards[1], false, fk.ReasonDraw, player.id, self.name)
                end
              elseif choice11 == "hx__taohui_e" then
                local cards = player.room:getCardsFromPileByRule(".|.|.|.|.|equip")
                if #cards > 0 then
                  room:obtainCard(player, cards[1], false, fk.ReasonDraw, player.id, self.name)
                end
              end
            end
            if equip > 0 then
              player.room:addPlayerMark(player, "@hx__taohui-card", equip)
            end
        end
    end
    if hasRedCard then
      player:drawCards(1, self.name)
      room:changeMaxHp(player, 1)
    end
    if player.room:askForSkillInvoke(player, self.name, data, "韬晦：你可以视为使用一张【决斗】(若重铸了黑色牌则该【决斗】的目标角色无法使用红色牌响应)。") then
      local targets = room:getOtherPlayers(player, false)
      if #targets == 0 then return end
      local targetIds = table.map(targets, Util.IdMapper)
      local to = room:askForChoosePlayers(player, targetIds, 1, 1, "#hx__taohui-invoke", self.name, true)
      if #to == 0 then return end
      local p = room:getPlayerById(to[1])
      if hasBlackCard then
        player.room:addPlayerMark(p, "@hx__taohui-mark", 1)
      end
      if p then
        room:useVirtualCard("duel", nil, player, p, self.name, false)
        room:setPlayerMark(p,"@hx__taohui-mark", 0)
      end
    end
  end,
}
local hx__taohui_prohibit = fk.CreateProhibitSkill{
  name = "#hx__taohui_prohibit",
  prohibit_use = function(self, player, card)
    if player:getMark("@hx__taohui-mark") > 0 and card:getColorString() == "red" then return true end
  end,
  prohibit_response = function(self, player, card)
    if player:getMark("@hx__taohui-mark") > 0 and card:getColorString() == "red" then return true end
  end,
}
local hx__taohui_card = fk.CreateMaxCardsSkill{
  name = "#hx__taohui_card",
  mute = true,
  frequency = Skill.Compulsory,
  correct_func = function(self, player)
      if player:hasSkill(self) then
        return player:getMark("@hx__taohui-card")
      end
  end
}

huixiangqy__spsimayi:addSkill(hx__taohui)
hx__taohui:addRelatedSkill(hx__taohui_prohibit)
hx__taohui:addRelatedSkill(hx__taohui_card)

local hx__zhabing_card = fk.CreateMaxCardsSkill{
  name = "#hx__zhabing_card",
  mute = true,
  frequency = Skill.Compulsory,
  correct_func = function(self, player)
      if player:hasSkill(self) then
        return 3
      end
  end
}

local hx__zhabing = fk.CreateTriggerSkill {
  name = "hx__zhabing",
  events = {fk.TurnEnd},
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) and target == player then
      local events = player.room.logic:getActualDamageEvents(1, function(e) return e.data[1].from == player end,Player.HistoryRound)
      return #events == 0
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if player.room:askForSkillInvoke(player, self.name, data, "诈病：回复一点体力，或点取消你获得效果：每轮开始时令你造成的伤害+1直到你造成伤害（该效果可叠加）") then
      room:recover({
        who = player,
        num = 1,
        skillName = self.name
      })
    else
      room:addPlayerMark(player, "@@hx__zhabing_candamage")
    end
  end,
}

local hx__zhabing_effect = fk.CreateTriggerSkill {
  name = "#hx__zhabing_effect",
  frequency = Skill.Compulsory,
  events = {fk.Damage,fk.RoundStart,fk.DamageCaused},
  can_trigger = function(self, event, target, player, data)
    if event == fk.RoundStart then
      return player:hasSkill(self) and player:getMark("@@hx__zhabing_candamage") ~= 0
    elseif data.damage then
      return player:hasSkill(self) and target == player and player:getMark("@@hx__zhabing_candamage") ~= 0
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local x = player:getMark("@hx__zhabing_damage")
    if event == fk.RoundStart then
      player.room:addPlayerMark(player, "@hx__zhabing_damage", player:getMark("@@hx__zhabing_candamage"))
    elseif data.damage and data.damage > 0 then
      data.damage = data.damage + x
      room:setPlayerMark(player, "@hx__zhabing_damage", 0)
      room:setPlayerMark(player, "@@hx__zhabing_candamage", 0)
    end
  end,
}

huixiangqy__spsimayi:addSkill(hx__zhabing)
hx__zhabing:addRelatedSkill(hx__zhabing_card)
hx__zhabing:addRelatedSkill(hx__zhabing_effect)


local hx__fankui = fk.CreateTriggerSkill{
  name = "hx__fankui",
  anim_type = "offensive",
  events = {fk.Damaged, fk.Damage},
  can_trigger = function(self, event, target, player, data)
    return target == player and (event == fk.Damaged or event == fk.Damage) 
      and player:hasSkill(self) and player:usedSkillTimes(self.name, Player.HistoryTurn) < 2
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local judge = {
      who = player,
      reason = self.name,
      pattern = ".|.|.",
    }
    room:judge(judge)
    local suit = judge.card:getSuitString()
    local recorded = tostring(player:getMark("hx__fankuiRecord") or "")
    local suits = recorded and recorded:split("+") or {}
    if not table.contains(suits, suit) then
      table.insert(suits, suit)
      room:addPlayerMark(player, "hx__fankui_suitrecord", 1)
      room:setPlayerMark(player, "hx__fankuiRecord", table.concat(suits, "+"))
      local card_suits_table = { spade="♠", club="♣", heart="♥", diamond="♦" }
      room:setPlayerMark(player, "@hx__fankui", table.concat(table.map(suits, function(s) return card_suits_table[s] end), ""))
    end
    local x = data.damage
    local target_role = (event == fk.Damaged) and data.from or data.to
    local choices = {"hx__fankui1", "hx__fankui2"}
    if player:getMark("hx__fankui_suitrecord") >= 4 then
      table.insert(choices, "beishui")
    end
    local choice = room:askForChoice(player, choices,self.name, "#hx__fankui-choose")
    if choice == "beishui" then
      room:setPlayerMark(player, "hx__fankuiRecord", 0)
      room:setPlayerMark(player, "@hx__fankui", 0)
      room:setPlayerMark(player, "hx__fankui_suitrecord", 0)
    end
    if choice == "hx__fankui1" or choice == "beishui" then
      room:obtainCard(player, judge.card, false, fk.ReasonPrey)
      if target_role and target_role:isAlive() and not target_role:isNude() then
        room:throwCard(room:askForCardsChosen(player, target_role,x,x,"he",self.name), self.name, target_role, player)
      end
    end
    if choice == "hx__fankui2" or choice == "beishui" then
      if target_role and target_role:isAlive() and not target_role:isNude() then
        local card = room:askForCardChosen(player, target_role, "he", self.name)
        room:obtainCard(player.id, card, false, fk.ReasonPrey)
      end
      local to = room:askForChoosePlayers(player, table.map(room:getOtherPlayers(player, false),
    Util.IdMapper), 1, 1, "#hx__fankui-choose_target", self.name, true)
      if #to > 0 then
        local to = room:getPlayerById(to[1])
        to:drawCards(x, self.name)
      end
    end
  end
}

Fk:loadTranslationTable{
  ["#hx__fankui-choose"] = "请选择一项(x为伤害值)：",
  ["hx__fankui1"] = "获得判定牌，弃置伤害来源或目标x张牌",
  ["hx__fankui2"] = "获得目标一张牌，令一名其他角色摸x张牌",
  ["beishui"] = "背水：清空“反馈”记录的花色",
  ["@hx__fankui"] = "反馈花色:",
  ["#hx__fankui-choose_target"] = "请选择一名摸牌的角色",
}

local hx__guicai = fk.CreateTriggerSkill{
  name = "hx__guicai",
  anim_type = "control",
  events = {fk.AskForRetrial},
  can_trigger = function(self, event, target, player, data)
      return player:hasSkill(self.name) and not player.dead
  end,
  on_cost = function(self, event, target, player, data)
      local room = player.room
      return player.room:askForSkillInvoke(player, self.name, data)
  end,
  on_use = function(self, event, target, player, data)
      local room = player.room
      local suits = {"spade", "heart", "club", "diamond"}
      local numbers = {}
      for i = 1, 13 do
          table.insert(numbers, tostring(i))
      end
      local suit = room:askForChoice(player, suits, self.name, "#hx__guicai-suit")
      local number = tonumber(room:askForChoice(player, numbers, self.name, "#hx__guicai-number"))
      local cardFound = nil
      local card2Found = nil
      for _, id in ipairs(room.draw_pile) do
          local card11 = Fk:getCardById(id)
          if card11:getSuitString() == suit and not cardFound then
              cardFound = id
          end
          if card11.number == number and not card2Found then
              card2Found = id
          end
      end
      if cardFound then
          local thecard = Fk:getCardById(cardFound)
          if thecard then
              self.cost_data = thecard
              player.room:retrial(self.cost_data, player, data, self.name)
              room:sendLog{
                  type = "#hx__fankui_change1",
                  from = player.id,
                  arg = cardFound,
              }
          end
      end
      if card2Found then
          room:obtainCard(player, card2Found, false, fk.ReasonPrey)
          room:sendLog{
              type = "#hx__fankui_change2",
              from = player.id,
          }
      end
  end
}

huixiangqy__mousimayi:addSkill(hx__fankui)
huixiangqy__mousimayi:addSkill(hx__guicai)

Fk:loadTranslationTable{
  ["#hx__fankui_change1"] = "%from用牌堆中的一张与其选择的花色同花色的牌代替了判定牌。",
  ["#hx__fankui_change2"] = "%from从牌堆中获得了一张与其选择的点数同点数的牌。",
}

Fk:loadTranslationTable{
  ["huixiangqy__mousimayi"] = "谋司马懿",
  ["designer:huixiangqy__mousimayi"] = "非电竞恐龙",
  ["hx__fankui"] = "反馈",
  [":hx__fankui"] = "每回合限两次，当你受到或造成伤害后，你可以进行一次判定，如果判定牌的花色未被“反馈”记录，则记录此种花色。可以选择一项：1.获得判定牌且弃置伤害来源或目标角色的X张牌；2.获得伤害来源或目标角色的一张牌且令一名其他角色摸X张牌（X为你受到或造成的伤害值）；背水：清空“反馈”所记录的至少四种花色。",
  ["hx__guicai"] = "鬼才",
  [":hx__guicai"] = "当一名角色的判定牌生效前，你可以指定1个花色，然后随机从牌堆中用一张该花色的牌代替之，若如此做，你可以指定一个点数从牌堆中获得一张同点数的牌。",
  ["#hx__guicai-suit"] = "请选择花色",
  ["#hx__guicai-number"] = "请选择点数",
  ["$hx__fankui1"] = "转守为攻，以静制动。",
  ["$hx__fankui2"] = "早知今日，何必当初。",
  ["$hx__guicai1"] = "天命，也由我来定！",
  ["$hx__guicai2"] = "司马氏，乃天命之所加矣！", 
  ["~huixiangqy__mousimayi"] = "天煞孤星，这都是命中注定的吧。",
}


local hx__tianyi = fk.CreateActiveSkill{
  name = "hx__tianyi",
  anim_type = "offensive",
  prompt = "#hx__tianyi",
  max_card_num = 0,
  target_num = 1,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  card_filter = Util.FalseFunc,
  target_filter = function(self, to_select, selected)
    return #selected == 0 and to_select ~= Self.id and Self:canPindian(Fk:currentRoom():getPlayerById(to_select),true)
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.tos[1])
    room:drawCards(player, 1, self.name)
    local pindian = player:pindian({target}, self.name)
    room:sendLog{
      type = "#hx__tianyi_pindian",
      from = player.id,
    }
    if pindian.results[target.id].winner == player then
      local slash = Fk:cloneCard('slash')
      slash.skillName = self.name
      room:useCard({
        from = player.id,
        tos = {{target.id}},
        card = slash,
        extraUse = true,
        disresponsiveList = table.map(room.alive_players, Util.IdMapper),
      })
    else
      room:addPlayerMark(player, "@hx__tianyi_chusha", 1)
      player.room:obtainCard(player.id, pindian.fromCard)
    end
  end
}
local hx__tianyi_delay = fk.CreateTriggerSkill{
  name = "#hx__tianyi_delay",
  mute = true,
  events = {fk.PindianCardsDisplayed},
  can_trigger = function(self, event, target, player, data)
    return data.from == player and data.reason == "hx__tianyi"
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    data.fromCard.number = math.min(data.fromCard.number + player:getAttackRange(), 13)
  end,
}
local hx__tianyi_remove = fk.CreateTriggerSkill{
  name = "#hx__tianyi_remove",
  mute = true,
  frequency = Skill.Compulsory,
  events = {fk.TurnEnd},
  can_trigger = function(self, event, target, player, data)
     return player:hasSkill(self) and player:getMark("@hx__tianyi_chusha") > 0
  end,
  on_use = function(self, event, target, player, data)
    player.room:setPlayerMark(player, "@hx__tianyi_chusha", 0)
  end,
}

local hx__tianyi_chusha = fk.CreateTargetModSkill{
  name = "#hx__tianyi_chusha",
  residue_func = function(self, player, skill, scope)
    if player:hasSkill(self) and skill.trueName == "slash_skill"
      and scope == Player.HistoryPhase and player:getMark("@hx__tianyi_chusha") > 0 then
      return 1
    end
  end,
}
huixiangqy__jietaishici:addSkill(hx__tianyi)
hx__tianyi:addRelatedSkill(hx__tianyi_delay)
hx__tianyi:addRelatedSkill(hx__tianyi_remove)
hx__tianyi:addRelatedSkill(hx__tianyi_chusha)

local hx__tuwei = fk.CreateTriggerSkill{
  name = "hx__tuwei",
  events = {fk.AfterCardTargetDeclared},
  anim_type = "control",
  can_trigger = function(self, event, target, player, data)
    return target == player and
      data.card.trueName == "slash" and
      player:hasSkill(self) and #TargetGroup:getRealTargets(data.tos) == 1 and
      player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local choices = {"tuwei_damage", "tuwei_extra", "beishui"}
    local choice = room:askForChoice(player, choices, self.name, "#hx__tuwei-choose")
    self.cost_data = choice
    if choice == "tuwei_damage" or choice == "beishui" then
      data.additionalDamage = (data.additionalDamage or 0) + 1
    end
    if choice == "tuwei_extra" or choice == "beishui" then
      local extratargets = room:getUseExtraTargets(data)
      if #extratargets > 0 then 
        local tos = room:askForChoosePlayers(player, extratargets, 1, 1,
          "#hx__tuwei-extra-target:::" .. data.card:toLogString(), "hx__tuwei", true)
        if #tos > 0 then
          table.forEach(tos, function (id)
            table.insert(data.tos, {id})
          end)
        end
      end
    end
    if choice == "beishui" then
      room:loseHp(player, 1, self.name)
    end
  end
}

huixiangqy__jietaishici:addSkill(hx__tuwei)

Fk:loadTranslationTable{
  ["#hx__tianyi_pindian"] = "%from的拼点牌点数增加了X（X为其的攻击范围），因此赢的人可能是他",
  ["tuwei_damage"] = "令此【杀】伤害+1",
  ["tuwei_extra"] = "此【杀】可额外指定一个目标",
  ["beishui"] = "背水",
  ["#hx__tuwei-choose"] = "突围：请选择一项",
  ["#hx__tuwei-extra-target"] = "突围：请选择要额外指定的目标",
}

Fk:loadTranslationTable{
  ["huixiangqy__jietaishici"] = "界太史慈",
  ["designer:huixiangqy__jietaishici"] = "非电竞恐龙",
  ["hx__tianyi"] = "天义",
  [":hx__tianyi"] = "出牌阶段限一次，你可以摸一张牌，与一名其他角色拼点，此次你的拼点牌点数+X（X为你的攻击范围）。若你赢，你视为对其使用一张不可响应的【杀】（不计入次数且无视距离），若你没赢，则你可以获得自己拼点的牌且本回合可以多使用一张【杀】。",
  ["#hx__tianyi"] = "你可以与一名其他角色拼点",
  ["@hx__tianyi_chusha"] = "可多使用杀",
  ["hx__tuwei"] = "突围",
  [":hx__tuwei"] = "每回合限一次，当你使用【杀】指定唯一目标后，你可以选择一项：1.令此【杀】伤害+1；2.此【杀】可额外指定一个目标；背水：失去1点体力。",
  ["$hx__tianyi1"] = "无名之贼，可敢与我一战乎？",
  ["$hx__tianyi2"] = "将军之托，子义，必以死报之！",
  ["$hx__tuwei1"] = "刘繇虽亡，余部尚勇。吾愿为将军说之。",
  ["$hx__tuwei2"] = "此身、此武，只为秉义而战！",
  ["~huixiangqy__jietaishici"] = "大业未竟，奈何，天不假年……",
}



Fk:loadTranslationTable{
  ["huixiangqy__spzhugeliang"] = "SP诸葛亮",
  ["designer:huixiangqy__spzhugeliang"] = "非电竞恐龙",
  ["hx__sheru"] = "舌儒",
  [":hx__sheru"] = "出牌阶段限两次，你可以与一名其他角色拼点，若你赢，你获得双方所有拼点牌并摸一张牌，若你输，则该技能失效直到回合结束。",
  ["#hx__sheru-confirm"] = "舌儒：你可以选择一名其他角色与其再次拼点",
  ["hx__lianmeng"] = "联盟",
  ["#hx__lianmeng_juexing"] = "联盟",
  ["#hx__lianmeng-juexing-choose"] = "联盟：请选择获得技能的角色",
  ["@hx__lianmeng_mark"] = "盟",
  [":hx__lianmeng"] = "觉醒技，游戏开始时、准备阶段开始时、当你参与拼点时，你获得一个“盟”标记，你至多拥有7个“盟”标记，你的回合结束时，若你的“盟”标记达到了7，你选择一名角色获得技能“制衡”和“振鞘”，然后你失去“联盟”。",
  ["hx__zhiheng"] = "制衡",
  [":hx__zhiheng"] = "出牌阶段限一次，你可以弃置任意张牌并摸等量的牌。若你以此法弃置了所有的手牌，你多摸一张牌。",
  ["#hx__zhiheng"] = "制衡：你可以弃置任意张牌并摸等量的牌，若弃置了所有的手牌，多摸一张牌",
  ["hx__zhenqiao"] = "振鞘",
  [":hx__zhenqiao"] = "锁定技，你的攻击范围+1；当你使用【杀】指定目标后，若你的装备区没有武器牌，则此【杀】额外结算一次。",
  ["$hx__sheru1"] = "当年仲翔在会稽太守王朗账下，就曾劝主投降孙策。",
  ["$hx__sheru2"] = "不想如今归顺东吴后，又要劝主降曹，看来是旧病复发也！",
  ["$hx__lianmeng1"] = "苏秦佩六国相印，张仪两次为秦国宰相，二人皆有匡扶国家之大智大勇，非比那欺弱怕强，苟安避祸之人！",
  ["$hx__lianmeng2"] = "君等未见曹操一兵一卒，便闻风丧胆，畏惧请降，如此还敢嘲笑苏秦、张仪吗？",
  ["$hx__zhiheng"] = "不如将先生高见说于我家主公，孙刘两家联手共同抗曹，方为正经大事，老将军说的极是！",
  ["$hx__zhenqiao"] = "今曹操祖宗为汉臣、食汉禄，子孙不思报效，反怀篡逆之心！不是汉贼又是什么？",
  ["~huixiangqy__spzhugeliang"] = "悠悠苍天，何薄于我？",
}
local hx__zhiheng = fk.CreateActiveSkill{
  name = "hx__zhiheng",
  anim_type = "drawcard",
  min_card_num = 1,
  target_num = 0,
  prompt = "#hx__zhiheng",
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  card_filter = function(self, to_select, selected)
    return not Self:prohibitDiscard(Fk:getCardById(to_select))
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local hand = player:getCardIds(Player.Hand)
    local more = #hand > 0
    for _, id in ipairs(hand) do
      if not table.contains(effect.cards, id) then
        more = false
        break
      end
    end
    room:throwCard(effect.cards, self.name, player, player)
    if not player.dead then
      room:drawCards(player, #effect.cards + (more and 1 or 0), self.name)
    end
  end
}

local hx__zhenqiao = fk.CreateTriggerSkill{
  name = "hx__zhenqiao",
  anim_type = "offensive",
  frequency = Skill.Compulsory,
  events = {fk.TargetSpecified},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and data.card.trueName == "slash" and data.firstTarget
      and #player:getEquipments(Card.SubtypeWeapon) == 0
  end,
  on_use = function(self, event, target, player, data)
    data.additionalEffect = (data.additionalEffect or 0) + 1
  end,
}
local hx__zhenqiao_attackrange = fk.CreateAttackRangeSkill{
  name = "#hx__zhenqiao_attackrange",
  frequency = Skill.Compulsory,
  main_skill = hx__zhenqiao,
  correct_func = function (self, from, to)
    if from:hasSkill(hx__zhenqiao) then
      return 1
    end
    return 0
  end,
}
hx__zhenqiao:addRelatedSkill(hx__zhenqiao_attackrange)

local hx__sheru = fk.CreateActiveSkill{
  name = "hx__sheru",
  anim_type = "drawcard",
  card_num = 0,
  target_num = 1,
  can_use = function(self, player)
    if player:isKongcheng() then return false end
    return player:usedSkillTimes(self.name, Player.HistoryPhase) < 2
  end,
  card_filter = Util.FalseFunc,
  target_filter = function(self, to_select, selected)
    if #selected > 0 or to_select == Self.id then return false end
    return Self:canPindian(Fk:currentRoom():getPlayerById(to_select))
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.tos[1])
    local pindian = player:pindian({target}, self.name)
    if pindian.results[target.id].winner == player then
      player.room:drawCards(player, 1, self.name)
      local ids = {}
      for _, card in ipairs({pindian.fromCard, pindian.results[target.id].toCard}) do
        if room:getCardArea(card) == Card.DiscardPile then
          table.insertIfNeed(ids, card:getEffectiveId())
        end
      end
      if #ids > 0 and not player.dead then
        room:moveCards({
          ids = ids,
          to = player.id,
          toArea = Player.Hand,
          moveReason = fk.ReasonPrey,
          proposer = player.id,
          skillName = self.name,
        })
      end
    else
      room:invalidateSkill(player, self.name, "-turn")
    end
  end,
}

local hx__lianmeng = fk.CreateTriggerSkill{
  name = "hx__lianmeng",
  events = {fk.PindianResultConfirmed,fk.EventPhaseStart,fk.GameStart},
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    if player:getMark("@hx__lianmeng_mark") < 7 and player:hasSkill(self) then
      if event == fk.PindianResultConfirmed then
        return (data.from == player or data.to == player)
      end
      if event == fk.EventPhaseStart then
        return player.phase == Player.Start
      end
      if event == fk.GameStart then
        return true
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:addPlayerMark(player, "@hx__lianmeng_mark", 1)
  end,
}
local hx__lianmeng_juexing = fk.CreateTriggerSkill{
  name = "#hx__lianmeng_juexing",
  anim_type = "special",
  events = {fk.EventPhaseEnd},
  frequency = Skill.Wake,
  can_trigger = function(self, event, target, player, data)
      return player:hasSkill(self.name) and player:usedSkillTimes(self.name, Player.HistoryGame) == 0 and player.phase == Player.Finish
  end,
  can_wake = function(self, event, target, player, data)
      return player:getMark("@hx__lianmeng_mark") >= 7
  end,
  on_use = function(self, event, target, player, data)
      local room = player.room
      player:broadcastSkillInvoke("hx__lianmeng")
      local to = room:askForChoosePlayers(player, table.map(room.alive_players, Util.IdMapper), 1, 1,
      "#hx__lianmeng-juexing-choose", self.name, false)
      local tar = room:getPlayerById(to[1])
      if #to > 0 and not tar:hasSkill("hx__zhiheng", true) then
        room:handleAddLoseSkills(tar, "hx__zhiheng", nil,true,false)
      end
      if #to > 0 and not tar:hasSkill("hx__zhenqiao", true) then
        room:handleAddLoseSkills(tar, "hx__zhenqiao", nil,true,false)
      end
      room:handleAddLoseSkills(player, "-hx__lianmeng", nil,true,false)
  end,
}


huixiangqy__spzhugeliang:addSkill(hx__sheru)
huixiangqy__spzhugeliang:addSkill(hx__lianmeng)
hx__lianmeng:addRelatedSkill(hx__lianmeng_juexing)
huixiangqy__spzhugeliang:addRelatedSkill(hx__zhenqiao)
huixiangqy__spzhugeliang:addRelatedSkill(hx__zhiheng)


Fk:loadTranslationTable{
  ["huixiangqy__jiecaoang"] = "界曹昂",
  ["designer:huixiangqy__jiecaoang"] = "非电竞恐龙",
  ["hx__kangkai"] = "慷忾",
  [":hx__kangkai"] = "当一名角色成为【杀】的目标后，你可以摸一张牌，然后交给其一张牌并展示之。若此牌为装备牌，该角色可以使用此牌。然后若该角色受到了此【杀】的伤害，你摸一张牌。",
  ["hx__jueying"] = "绝影",
  ["#hx__jueying_recover"] = "绝影",
  [":hx__jueying"] = "限定技，出牌阶段时，你可以废除自己的一个装备栏并选择一名角色获得【飞影】和【马术】。你以此法选择的角色脱离濒死状态时，你可以恢复一个装备栏。",
  ["$hx__kangkai1"] = "典将军，比比看谁杀敌更多！",
  ["$hx__kangkai2"] = "尔等叛贼，来一个我杀一个！",
  ["$hx__jueying1"] = "骨肉之恩，亦当以骨肉报之！",
  ["$hx__jueying2"] = "父亲上马，孩儿随后便来！",
  ["~huixiangqy__jiecaoang"] = "吾全父名，父成吾名……",
  ["#hx__kangkai-invoke"] = "慷忾：你可以摸一张牌，再交给 %dest 一张牌，然后若该角色受到了此【杀】的伤害，你摸一张牌。",
  ["#hx__kangkai-self"] = "慷忾：你可以摸一张牌",
  ["#hx__kangkai-give"] = "慷忾：选择一张牌交给 %dest",
  ["#hx__kangkai-use"] = "慷忾：你可以使用%arg",
  ["#hx__jueying-feichu"] = "请选择要废除的装备栏",
  ["#hx__jueying-choose"] = "请选择获得【飞影】的角色",
  ["#hx__jueying_prompt"] = "绝影：你可以恢复一个装备栏",
  ["#hx__jueying-recover"] = "请选择要恢复的装备栏",
  ["#hx__jueying-juexing"] = "绝影：你可以废除自己的一个装备栏并选择一名其他角色获得【飞影】和【马术】",
  ["hx__feiying"] = "飞影",
  [":hx__feiying"] = "锁定技，其他角色计算与你距离+1。",
  ["hx__mashu"] = "马术",
  [":hx__mashu"] = "锁定技，你计算与其他角色距离-1。",
}
local hx__feiying = fk.CreateDistanceSkill{
  name = "hx__feiying",
  correct_func = function(self, from, to)
    if to:hasSkill(self) then
      return 1
    end
    return 0
  end,
}

local hx__kangkai = fk.CreateTriggerSkill{
  name = "hx__kangkai",
  anim_type = "support",
  events = {fk.TargetConfirmed},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and data.card.trueName == "slash"
  end,
  on_cost = function (self, event, target, player, data)
    local prompt = (player.id == data.to) and "#hx__kangkai-self" or "#hx__kangkai-invoke::"..data.to
    return player.room:askForSkillInvoke(player, self.name, nil, prompt)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(data.to)
    player:drawCards(1, self.name)
    room:addPlayerMark(player,"hx__kangkai_mark", 1)
    if player == to or player:isNude() or to.dead then return end
    local cards = room:askForCard(player, 1, 1, true, self.name, false, ".", "#hx__kangkai-give::"..to.id)
    if #cards > 0 then
      room:moveCardTo(cards, Card.PlayerHand, to, fk.ReasonGive, self.name, nil, true, player.id)
      to:showCards(cards)
      local card = Fk:getCardById(cards[1])
      if card.type == Card.TypeEquip and not to.dead and not to:isProhibited(to, card) and not to:prohibitUse(card) and
        table.contains(to:getCardIds("h"), cards[1]) and
        room:askForSkillInvoke(to, self.name, data, "#hx__kangkai-use:::"..card:toLogString()) then
        room:useCard({
          from = to.id,
          tos = {{to.id}},
          card = card,
        })
      end
    end
  end,
  refresh_events = {fk.CardUseFinished},
  can_refresh = function (self, event, target, player, data)
    return player:hasSkill(self) and data.card.trueName == "slash" and data.damageDealt and player:getMark("hx__kangkai_mark") ~= 0 
    and (target == player or target ~= player) 
  end,
  on_refresh = function (self, event, target, player, data)
    local room = player.room
    local tos = TargetGroup:getRealTargets(data.tos)
    for _, t in ipairs(tos) do
      if data.damageDealt[t] then
        player:drawCards(1, self.name)
      end
    end
    room:setPlayerMark(player,"hx__kangkai_mark", 0)
  end
}

local hx__jueying = fk.CreateActiveSkill{
  name = "hx__jueying",
  frequency = Skill.Limited,
  card_num = 0,
  target_num = 1,
  card_filter = Util.FalseFunc,
  target_filter = function(self, to_select, selected)
    return #selected == 0
  end,
  prompt = "#hx__jueying-juexing",
  can_use = function(self, player)
    return player:hasSkill(self) and #player:getAvailableEquipSlots() > 0 and player:usedSkillTimes(self.name, Player.HistoryGame) == 0
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local to = room:getPlayerById(effect.tos[1])
    local choice = room:askForChoice(player, player:getAvailableEquipSlots(),self.name, "#hx__jueying-feichu", false)
    room:abortPlayerArea(player, choice)
    if player.dead then return end
    if #choice > 0 then
      room:handleAddLoseSkills(to,"hx__feiying", nil, true, false)
      room:handleAddLoseSkills(to,"hx__mashu", nil, true, false)
      room:addPlayerMark(to,"hx__jueying_mark", 1)
    end
  end,
}

local hx__jueying_recover = fk.CreateTriggerSkill{
  name = "#hx__jueying_recover",
  prompt = "#hx__jueying_prompt",
  events = {fk.AfterDying},
  can_trigger = function(self, event, target, player, data)
    if event == fk.AfterDying then
      return player:hasSkill(self) and target ~= player and not player:isNude() and target:getMark("hx__jueying_mark") ~= 0
      and #player:getAvailableEquipSlots() > 0
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local slots = table.simpleClone(player.sealedSlots)
    table.removeOne(slots, Player.JudgeSlot)
    local hx__jueying_recover = room:askForChoice(player, slots, self.name, "#hx__jueying-recover")
    room:resumePlayerArea(player,{hx__jueying_recover})
    room:setPlayerMark(target,"hx__jueying_mark", 0)
  end,
}
local hx__mashu = fk.CreateDistanceSkill{
  name = "hx__mashu",
  frequency = Skill.Compulsory,
  correct_func = function(self, from, to)
    if from:hasSkill(self) then
      return -1
    end
  end,
}
huixiangqy__jiecaoang:addSkill(hx__kangkai)
huixiangqy__jiecaoang:addSkill(hx__jueying)
huixiangqy__jiecaoang:addSkill(hx__jueying_recover)
huixiangqy__jiecaoang:addRelatedSkill(hx__feiying)
huixiangqy__jiecaoang:addRelatedSkill(hx__mashu)


Fk:loadTranslationTable{
  ["huixiangqy__jiemaliang"] = "界马良",
  ["designer:huixiangqy__jiemaliang"] = "非电竞恐龙",
  ["hx__zishu"] = "自书",
  ["hx__zishu_pile"] = "自书牌",
  [":hx__zishu"] = "锁定技，你的回合外，你将获得的牌置于武将牌上，准备阶段，你获得这些牌；你的回合内，当你不因此技能获得牌时，摸一张牌。",
  ["hx__yingyuan"] = "应援",
  [":hx__yingyuan"] = "当你于回合内使用的基本牌或普通锦囊牌结算结束后，若此牌在弃牌堆内，你可以将之交给一名其他角色（相同牌名的牌每回合限一次）。若如此做，每回合限一次，你令其选择一项：1.令你回复1点体力获得1点护甲；2.交给你一张牌。",
  ["#hx__yingyuan-card"] = "应援：你可以将 %arg 交给一名其他角色",
  ["$hx__zishu1"] = "我意已决，诸兄何复多言？",
  ["$hx__zishu2"] = "此去如若不成，吾宁殉志而终。",
  ["$hx__yingyuan1"] = "皇叔辅者少有，良当即时应召。",
  ["$hx__yingyuan2"] = "今幸明主亲召，良安可不应乎？",
  ["~huixiangqy__jiemaliang"] = "此生行忠守义，已无愧我心。",
  ["$huixiangqy__jiemaliang_win_audio"] = "良与主公一道，志为兴汉奋身！",
  ["hx__yingyuan-recover"] = "令界马良回复1点体力获得1点护甲",
  ["hx__yingyuan-give"] = "交给界马良一张牌",
  ["#hx__yingyuan-give"] = "请选择一张牌",
} 
local huixiangqy__jiemaliangwin = fk.CreateActiveSkill{ name = "huixiangqy__jiemaliang_win_audio" }
huixiangqy__jiemaliangwin.package = extension
Fk:addSkill(huixiangqy__jiemaliangwin)

local hx__zishu = fk.CreateTriggerSkill{
  name = "hx__zishu",
  events = {fk.AfterCardsMove,fk.EventPhaseProceeding},
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) then
      if event == fk.AfterCardsMove then
        if player ~= player.room.current then
          for _, move in ipairs(data) do
            if move.to == player.id and move.toArea == Player.Hand then
              return true
            end
          end
        elseif player.room.current == player then
          for _, move in ipairs(data) do
            if move.to == player.id and move.toArea == Player.Hand and move.skillName ~= self.name then
              return true
            end
          end
        end
      elseif player.phase == Player.Start then
        return true
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local cards = {}
    if event == fk.AfterCardsMove then
      if player ~= player.room.current then
        for _, move in ipairs(data) do
        if move.to == player.id and move.toArea == Player.Hand then
          for _, info in ipairs(move.moveInfo) do
            local id = info.cardId
            if room:getCardArea(id) == Card.PlayerHand and room:getCardOwner(id) == player then
              table.insert(cards, id)
            end
          end
        end
      end
      if #cards > 0 then
        player:addToPile("hx__zishu_pile", cards, false, self.name)
      end
      elseif player.room.current == player then
        room:notifySkillInvoked(player, self.name, "drawcard")
        player:drawCards(1, self.name)
      end
    elseif player.phase == Player.Start then
      if #player:getPile("hx__zishu_pile") > 0 then
        local cards = player:getPile("hx__zishu_pile")
        room:moveCards({
          ids = cards,
          from = player.id,
          to = player.id,
          toArea = Card.PlayerHand,
          moveReason = fk.ReasonPut,
          proposer = player.id,
          skillName = self.name,
        })
      end
    end
  end,
}

local hx__yingyuan = fk.CreateTriggerSkill{
  name = "hx__yingyuan",
  anim_type = "support",
  events = {fk.CardUseFinished},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self) and player.phase == Player.Play then
      local mark = player:getMark("hx__yingyuan-turn")
      if type(mark) ~= "table" or not table.contains(mark, data.card.trueName) then
        local cardlist = data.card:isVirtual() and data.card.subcards or {data.card.id}
        local room = player.room
        return #cardlist > 0 and table.every(cardlist, function (id)
          return room:getCardArea(id) == Card.Processing
        end)
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    local to = player.room:askForChoosePlayers(player, table.map(player.room:getOtherPlayers(player), Util.IdMapper), 1, 1,
      "#hx__yingyuan-card:::"..data.card:toLogString(), self.name, true)
    if #to > 0 then
      self.cost_data = to[1]
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local choices = {"hx__yingyuan-recover", "hx__yingyuan-give"}
    local cards = room:getSubcardsByRule(data.card, { Card.Processing })
    local to = room:getPlayerById(self.cost_data)
    room:moveCardTo(cards, Card.PlayerHand, to, fk.ReasonGive, self.name, nil, true, player.id)
    if player:getMark("hx__yingyuan-can") == 0 then
      local choice = room:askForChoice(to, choices, self.name)
      room:setPlayerMark(player,"hx__yingyuan-can", 1)
      if choice == "hx__yingyuan-recover" then
        room:recover({
          who = player,
          num = 1,
          skillName = self.name
        })
        room:changeShield(player, 1)
      else
        local card = room:askForCard(to, 1, 1, true, self.name, false, ".", "#hx__yingyuan-give::"..to.id)
        if #card > 0 then
          room:moveCardTo(card, Card.PlayerHand, player, fk.ReasonGive, self.name, nil, true, to.id)
        end
      end
    end
    if player.dead then return end
    room:addTableMark(player, "hx__yingyuan-turn", data.card.trueName)
  end,
}
local hx__yingyuan_remove = fk.CreateTriggerSkill{
  name = "#hx__yingyuan_remove",
  mute = true,
  frequency = Skill.Compulsory,
  events = {fk.TurnEnd},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and player:getMark("hx__yingyuan-can") > 0
  end,
  on_use = function(self, event, target, player, data)
    local room=player.room
    room:setPlayerMark(player,"hx__yingyuan-can", 0)
  end,
}

huixiangqy__jiemaliang:addSkill(hx__zishu)
huixiangqy__jiemaliang:addSkill(hx__yingyuan)
hx__yingyuan:addRelatedSkill(hx__yingyuan_remove)



Fk:loadTranslationTable{
  ["huixiangqy__xingzuoci"] = "星左慈",
  ["designer:huixiangqy__xingzuoci"] = "非电竞恐龙",
  ["hx__xianbian"] = "仙变",
  ["#hx__xianbian_mark"] = "仙变",
  [":hx__xianbian"] = "游戏开始时，你可以选择一种类型的牌。每回合限两次，一名角色使用非你选择的类型的牌时，你可以弃置一张你选择的类型的牌然后摸一张牌并将此牌的目标改为由你选择的一名角色，若如此做，你失去一点体力。",
  ["hx__dedao"] = "得道",
  [":hx__dedao"] = "限定技，你的出牌阶段，你可以弃置一张牌并令一名角色摸X张牌（X为弃置的牌的点数）。若如此做，你失去【仙变】且回复Y点体力（Y为你发动仙变的次数）。",
  ["$hx__xianbian1"] = "眼之所见，皆为幻想。",
  ["$hx__xianbian2"] = "幻化之术谨知，为政者自当为国为民！",
  ["$hx__dedao1"] = "放下俗念，为道为仙！",
  ["$hx__dedao2"] = "死生存亡，命之形也！",
  ["~huixiangqy__xingzuoci"] = "凡俗琐事，不再牵扰……",
  ["#hx__xianbian-choicetype"] = "请选择两种类型的牌",
  ["#hx__xianbian-choice"] = "请选择一张牌",
  ["#hx__xianbian-choosetarget"] = "请选择此牌的新目标",
  ["hx__dedao-choose"] = "请选择摸牌的角色",
  ["@hx__xianbian"] = "仙变次数",
  ["@hx__xianbian_b"] = "仙变·基本",
  ["@hx__xianbian_t"] = "仙变·锦囊",
  ["@hx__xianbian_e"] = "仙变·装备",
  ["hx__basic"] = "基本牌",
  ["hx__equip"] = "装备牌",
  ["hx__trick"] = "锦囊牌",
  ["#hx__xianbian-invoke1"] = "请选择一张基本牌弃置",
  ["#hx__xianbian-invoke2"] = "请选择一张锦囊牌弃置",
  ["#hx__xianbian-invoke3"] = "请选择一张装备牌弃置",
}
local hx__xianbian_mark = fk.CreateTriggerSkill{
  name = "#hx__xianbian_mark",
  events = {fk.GameStart},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self)
  end,
  on_cost = function(self, event, target, player, data)
    local choices = {"hx__basic", "hx__equip", "hx__trick"}
    local choice = player.room:askForChoice(player,choices,self.name)
    if choice then
      self.cost_data = choice
      return true
    end
    return false
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:addPlayerMark(player,"@hx__xianbian",1)
    player:broadcastSkillInvoke("hx__xianbian")
    if self.cost_data == "hx__basic" then
      player.room:addPlayerMark(player, "@hx__xianbian_b", 1)
    elseif self.cost_data == "hx__trick" then
      player.room:addPlayerMark(player,"@hx__xianbian_t",1)
    elseif self.cost_data == "hx__equip" then
      player.room:addPlayerMark(player,"@hx__xianbian_e",1)
    end
  end,
}
local hx__xianbian = fk.CreateTriggerSkill{
  name = "hx__xianbian",
  events = {fk.CardUsing},
  can_trigger = function(self, event, target, player, data)
    local id_b = table.filter(player:getCardIds("he"), function(id) return Fk:getCardById(id).type == Card.TypeBasic end)
    local id_t = table.filter(player:getCardIds("he"), function(id) return Fk:getCardById(id).type == Card.TypeTrick end)
    local id_e = table.filter(player:getCardIds("he"), function(id) return Fk:getCardById(id).type == Card.TypeEquip end)
    if player:hasSkill(self) and data.card and player:usedSkillTimes(self.name, Player.HistoryTurn) < 2 then
      if player:getMark("@hx__xianbian_b") > 0 and #id_b > 0 then
        return data.card.type == Card.TypeTrick or data.card.type == Card.TypeEquip
      elseif player:getMark("@hx__xianbian_t") > 0 and #id_t > 0 then
        return data.card.type == Card.TypeEquip or data.card.type == Card.TypeBasic
      elseif player:getMark("@hx__xianbian_e") > 0 and #id_e > 0 then
        return data.card.type == Card.TypeBasic or data.card.type == Card.TypeTrick
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local originalTarget = TargetGroup.getRealTargets(data.tos)[1]
    local candidates = table.filter(room:getAlivePlayers(), function(p) return p.id ~= originalTarget end)
    if #candidates == 0 then return false end
    if player:getMark("@hx__xianbian_b") > 0 then
      local card = player.room:askForDiscard(player, 1, 1, true, self.name, false, ".|.|.|.|.|basic", "#hx__xianbian-invoke1", false)
      if #card > 0 then
        room:addPlayerMark(player,"@hx__xianbian",1)
        player:drawCards(1, self.name)
        local prompt = "#hx__xianbian-choosetarget:::"..data.card:toLogString()
        local target_p = room:askForChoosePlayers(player, table.map(candidates, Util.IdMapper), 1, 1, prompt, self.name, false)
        if #target_p > 0 then
          self.cost_data = {
            newTarget = target_p[1],
            cardName = data.card.trueName
          }
          data.tos = { { self.cost_data.newTarget } }
        end
        room:loseHp(player,1,self.name)
      end
    elseif player:getMark("@hx__xianbian_t") > 0 then
      local card = player.room:askForDiscard(player, 1, 1, true, self.name, false, ".|.|.|.|.|trick", "#hx__xianbian-invoke2", false)
      if #card > 0 then
        room:addPlayerMark(player,"@hx__xianbian",1)
        player:drawCards(1, self.name)
        local prompt = "#hx__xianbian-choosetarget:::"..data.card:toLogString()
        local target_p = room:askForChoosePlayers(player, table.map(candidates, Util.IdMapper), 1, 1, prompt, self.name, false)
        if #target_p > 0 then
          self.cost_data = {
            newTarget = target_p[1],
            cardName = data.card.trueName
          }
          data.tos = { { self.cost_data.newTarget } }
        end
        room:loseHp(player,1,self.name)
      end
    elseif player:getMark("@hx__xianbian_e") > 0 then
      local card = player.room:askForDiscard(player, 1, 1, true, self.name, false, ".|.|.|.|.|equip", "#hx__xianbian-invoke3", false)
      if #card > 0 then
        room:addPlayerMark(player,"@hx__xianbian",1)
        player:drawCards(1, self.name)
        local prompt = "#hx__xianbian-choosetarget:::"..data.card:toLogString()
        local target_p = room:askForChoosePlayers(player, table.map(candidates, Util.IdMapper), 1, 1, prompt, self.name, false)
        if #target_p > 0 then
          self.cost_data = {
            newTarget = target_p[1],
            cardName = data.card.trueName
          }
          data.tos = { { self.cost_data.newTarget } }
        end
        room:loseHp(player,1,self.name)
      end
    end
  end,
}

local hx__dedao = fk.CreateActiveSkill{
  name = "hx__dedao",
  anim_type = "drawcard",
  card_num = 1,
  target_num = 1,
  frequency = Skill.Limited,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryGame) == 0 and not player:isKongcheng()
  end,
  card_filter = function(self, to_select, selected)
    return #selected == 0 and
      not Self:prohibitDiscard(Fk:getCardById(to_select))
  end,
  target_filter = function(self, to_select, selected)
    return #selected == 0
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local to = room:getPlayerById(effect.tos[1])
    room:throwCard(effect.cards, self.name, player, player)
    if player.dead then return end
    local card = Fk:getCardById(effect.cards[1])
    local x = card.number
    local y = player:getMark("@hx__xianbian")
    room:drawCards(to, x,self.name)
    room:recover({
      who = player,
      num = y,
      skillName = self.name
    })
    room:setPlayerMark(player,"@hx__xianbian",0)
    room:setPlayerMark(player,"@hx__xianbian_b",0)
    room:setPlayerMark(player,"@hx__xianbian_t",0)
    room:setPlayerMark(player,"@hx__xianbian_e",0)
    room:handleAddLoseSkills(player,"-hx__xianbian", nil, true, false)
  end,
}

huixiangqy__xingzuoci:addSkill(hx__xianbian)
huixiangqy__xingzuoci:addSkill(hx__dedao)
hx__xianbian:addRelatedSkill(hx__xianbian_mark)



Fk:loadTranslationTable{
  ["huixiangqy__moucaochong"] = "谋曹冲",
  ["designer:huixiangqy__moucaochong"] = "非电竞恐龙",
  ["hx__chengxiang"] = "称象",
  [":hx__chengxiang"] = "判定阶段开始时或每当你受到1点伤害后，你可以亮出牌堆顶X张牌。然后你获得其中任意数量点数之和小于等于13的牌，将其余的牌进入弃牌堆。（X为你的体力上限）。",
  ["hx__renxin"] = "仁心",
  [":hx__renxin"] = "每轮限两次，每当一名角色即将受到伤害前/一名角色陷入濒死状态时，你可以从1.“判定阶段”，2.“摸牌阶段”，3.“出牌阶段”，4.“弃牌阶段”中选择两个阶段并弃置一张装备牌，你下个回合跳过所选择的阶段，然后防止此伤害/令其脱离濒死状态将体力值回复至一点。",
  ["hx__miaosuan"] = "妙算",
  [":hx__miaosuan"] = "锁定技，每当你发动两次“仁心”或发动“称象”获得的牌的点数和为13时，若你的体力上限不为13，你增加一点体力上限或摸X张牌（X为你已损失的体力值-3且至少为0）。",
  ["$hx__chengxiang1"] = "依我看，小事一桩！",
  ["$hx__chengxiang2"] = "父亲，父亲，看冲儿的！",
  ["$hx__renxin1"] = "施仁心，怜众生！",
  ["$hx__renxin2"] = "我身虽小，亦有仁心！",
  ["$hx__miaosuan1"] = "容我来，算上一算！",
  ["$hx__miaosuan2"] = "物以载之，校可知矣！",
  ["~huixiangqy__moucaochong"] = "父亲，父亲，你在哪里呀？",
}
Fk:addPoxiMethod{
  name = "hx__chengxiang_count",
  card_filter = function(to_select, selected, data)
    if table.contains(data[2], to_select) then return true end
    local n = Fk:getCardById(to_select).number
    for _, id in ipairs(data[2]) do
      n = n + Fk:getCardById(id).number
    end
    return n < 14
  end,
  feasible = function(selected)
    return true
  end,
}
local hx__chengxiang = fk.CreateTriggerSkill{
  name = "hx__chengxiang",
  anim_type = "masochism",
  events = {fk.Damaged,fk.EventPhaseProceeding},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) then
      if event == fk.Damaged and target == player then
        return true
      elseif event == fk.EventPhaseProceeding and player.phase == Player.Judge then
        return true
      end
    end
  end,
  on_trigger = function(self, event, target, player, data)
    if event == fk.Damaged then
      self.cancel_cost = false
      for i = 1, data.damage do
        if self.cancel_cost or not player:hasSkill(self) then break end
        self:doCost(event, target, player, data)
      end
    elseif event == fk.EventPhaseProceeding and player.phase == Player.Judge then
      return self:doCost(event, target, player, data)
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local y = player.maxHp
    local cards = room:getNCards(y)
    room:moveCards({
      ids = cards,
      toArea = Card.Processing,
      moveReason = fk.ReasonPut,
      proposer = player.id,
      skillName = self.name,
    })
    local get = room:askForArrangeCards(player, self.name, {cards},
    "#hx__chengxiang-choose", false, 0, {13, 13}, {0, 1}, ".", "hx__chengxiang_count", {{}, {cards[1]}})[2]
    room:moveCardTo(get, Player.Hand, player, fk.ReasonJustMove, self.name, "", true, player.id)
    cards = table.filter(cards, function(id) return room:getCardArea(id) == Card.Processing end)
    if #cards > 0 then
      room:moveCards({
        ids = cards,
        toArea = Card.DiscardPile,
        moveReason = fk.ReasonPutIntoDiscardPile,
      })
    end
    local n = 0
    for _, id in ipairs(get) do
      n = n + Fk:getCardById(id).number
    end
    if n == 13 and player.maxHp ~= 13 then
      player:broadcastSkillInvoke("hx__miaosuan")
      room:notifySkillInvoked(player, "hx__miaosuan")
      local x = player.maxHp - player.hp - 3
      local choices = {"hx__miaosuan_maxhp"}
      if x > 0 then
        table.insert(choices, "hx__miaosuan_draw")
      end
      local choice = room:askForChoice(player,choices,"hx__miaosuan")
      if choice == "hx__miaosuan_maxhp" then
        room:changeMaxHp(player, 1)
      elseif choice == "hx__miaosuan_draw" then
        room:drawCards(player, x, "hx__miaosuan")
      end
    end
  end
}
Fk:loadTranslationTable{
  ["hx__miaosuan_maxhp"] = "增加1点体力上限",
  ["hx__miaosuan_draw"] = "摸X张牌（X为你已损失的体力值-3）",
  ["#hx__chengxiang-choose"] = "获得任意点数之和小于或等于13的牌",
  ["hx__chengxiang_count"] = "称象",
  ["#hx__renxin-invoke"] = "仁心：你可以弃置一张装备牌，防止 %dest 受到的伤害/令其脱离濒死状态将体力值回复至一点",
  ["hx__judge"] = "判定阶段",
  ["hx__draw"] = "摸牌阶段",
  ["hx__play"] = "出牌阶段",
  ["hx__discard"] = "弃牌阶段",
  ["@hx__renxin_judge"] = "跳过·判定",
  ["@hx__renxin_draw"] = "跳过·摸牌",
  ["@hx__renxin_play"] = "跳过·出牌",
  ["@hx__renxin_discard"] = "跳过·弃牌",
  ["@hx__renxin"] = "仁心次数",
}

local hx__renxin = fk.CreateTriggerSkill{
  name = "hx__renxin",
  anim_type = "support",
  events = {fk.DamageInflicted, fk.EnterDying},
  can_trigger = function(self, event, target, player, data)
    local equipCards = table.filter(player:getCardIds("he"), function(id) 
      return Fk:getCardById(id).type == Card.TypeEquip 
    end)
    if player:hasSkill(self) and not player:isNude() and player:usedSkillTimes(self.name, Player.HistoryRound) < 2 and #equipCards > 0 then
      if event == fk.DamageInflicted then
        return true
      elseif event == fk.EnterDying then
        return true
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    local equipCard = player.room:askForDiscard(player, 1, 1, true, self.name, true, ".|.|.|.|.|equip", "#hx__renxin-invoke::"..target.id, true)
    if #equipCard > 0 then
      local choices = {}
      if player:getMark("@hx__renxin_judge") == 0 then
        table.insert(choices, "hx__judge")
      end
      if player:getMark("@hx__renxin_draw") == 0 then
        table.insert(choices, "hx__draw")
      end
      if player:getMark("@hx__renxin_play") == 0 then
        table.insert(choices, "hx__play")
      end
      if player:getMark("@hx__renxin_discard") == 0 then
        table.insert(choices, "hx__discard")
      end
      if #choices >= 2 then
        local selectedPhases = player.room:askForChoices(player, choices, 2, 2, self.name,".",false)
        if selectedPhases then
          self.cost_data = {selectedPhases, equipCard[1]}
          return true
        end
      end
      return false
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local selectedPhases = self.cost_data[1]
    local equipCardId = self.cost_data[2]
    room:throwCard(equipCardId, self.name, player, player)
    room:addPlayerMark(player,"@hx__renxin",1)
    if event == fk.DamageInflicted then
      data.damage = 0
    elseif event == fk.EnterDying then
      if target:isWounded() then
        room:recover { num = 1 - target.hp, skillName = self.name, who = target }
      end
    end
    for _, phase in ipairs(selectedPhases) do
      if phase == "hx__judge" then
        room:addPlayerMark(player, "@hx__renxin_judge", 1)
      elseif phase == "hx__draw" then
        room:addPlayerMark(player, "@hx__renxin_draw", 1)
      elseif phase == "hx__play" then
        room:addPlayerMark(player, "@hx__renxin_play", 1)
      elseif phase == "hx__discard" then
        room:addPlayerMark(player, "@hx__renxin_discard", 1)
      end
    end
  end,
}
local hx__renxin_skip = fk.CreateTriggerSkill {
  name = "#hx__renxin_skip",
  mute = true,
  events = { fk.EventPhaseChanging,fk.TurnEnd},
  frequency = Skill.Compulsory,
  anim_type = "masochism",
  can_trigger = function(self, event, target, player, data)
    if event == fk.EventPhaseChanging then
      return player:hasSkill(self) and player == target and  
      ((data.to == Player.Judge and player:getMark("@hx__renxin_judge") > 0 and player:getMark("hx__renxin_judge_skip") > 0) or
      (data.to == Player.Draw and player:getMark("@hx__renxin_draw") > 0 and player:getMark("hx__renxin_draw_skip") > 0) or
      (data.to == Player.Play and player:getMark("@hx__renxin_play") > 0 and player:getMark("hx__renxin_play_skip") > 0) or 
      (data.to == Player.Discard and player:getMark("@hx__renxin_discard") > 0 and player:getMark("hx__renxin_discard_skip") > 0) )
    elseif event == fk.TurnEnd then
      return player:hasSkill(self)
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
      if player:getMark("hx__renxin_judge_skip") > 0 and data.to == Player.Judge then
        player:skip(Player.Judge)
        room:setPlayerMark(player, "@hx__renxin_judge", 0)
        room:setPlayerMark(player, "hx__renxin_judge_skip", 0)
      elseif player:getMark("hx__renxin_draw_skip") > 0 and data.to == Player.Draw then
        player:skip(Player.Draw)
        room:setPlayerMark(player, "@hx__renxin_draw", 0)
        room:setPlayerMark(player, "hx__renxin_draw_skip", 0)
      elseif player:getMark("hx__renxin_play_skip") > 0 and data.to == Player.Play then
        player:skip(Player.Play)
        room:setPlayerMark(player, "@hx__renxin_play", 0)
        room:setPlayerMark(player, "hx__renxin_play_skip", 0)
      elseif player:getMark("hx__renxin_discard_skip") > 0 and data.to == Player.Discard then
        player:skip(Player.Discard)
        room:setPlayerMark(player, "@hx__renxin_discard", 0)
        room:setPlayerMark(player, "hx__renxin_discard_skip", 0)
      end
    if event == fk.TurnEnd then
      if player:getMark("@hx__renxin_judge") > 0 then
        room:addPlayerMark(player, "hx__renxin_judge_skip", 1)
      end
      if player:getMark("@hx__renxin_draw") > 0 then
        room:addPlayerMark(player, "hx__renxin_draw_skip", 1)
      end
      if player:getMark("@hx__renxin_play") > 0 then
        room:addPlayerMark(player, "hx__renxin_play_skip", 1)
      end
      if player:getMark("@hx__renxin_discard") > 0 then
        room:addPlayerMark(player, "hx__renxin_discard_skip", 1)
      end
    end
  end,
}
huixiangqy__moucaochong:addSkill(hx__chengxiang)
huixiangqy__moucaochong:addSkill(hx__renxin)
hx__renxin:addRelatedSkill(hx__renxin_skip)

local hx__miaosuan = fk.CreateTriggerSkill{
  name = "hx__miaosuan",
  anim_type = "support",
  frequency = Skill.Compulsory,
  events = {fk.AfterSkillEffect},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) and player.maxHp ~= 13 then
      if event == fk.AfterSkillEffect then
        return player:getMark("@hx__renxin") > 0 and player:getMark("@hx__renxin") % 2 == 0
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local x = player.maxHp - player.hp - 3
    local choices = {"hx__miaosuan_maxhp"}
    if x > 0 then
      table.insert(choices, "hx__miaosuan_draw")
    end
    if player:getMark("@hx__renxin") > 0 and player:getMark("@hx__renxin") % 2 == 0 then
      local choice = room:askForChoice(player,choices,"hx__miaosuan")
      if choice == "hx__miaosuan_maxhp" then
        room:changeMaxHp(player, 1)
      elseif choice == "hx__miaosuan_draw" then
        room:drawCards(player, x, "hx__miaosuan")
      end
      room:setPlayerMark(player,"@hx__renxin",0)
    end
  end,
}

huixiangqy__moucaochong:addSkill(hx__miaosuan)


Fk:loadTranslationTable{
  ["huixiangqy__mouxuchu"] = "谋许褚",
  ["designer:huixiangqy__mouxuchu"] = "非电竞恐龙",
  ["hx__luoyi"] = "裸衣",
  [":hx__luoyi"] = "摸牌阶段开始时，你亮出牌堆顶X张牌（X为你的体力上限），然后你可以选择获得其中的基本牌、锦囊牌、装备牌各一张。若如此做，你放弃摸牌，且直到你下回合开始，你使用【杀】或【决斗】造成伤害＋1。",
  ["hx__baoji"] = "暴击",
  [":hx__baoji"] = "当你使用的【杀】被【闪】抵消后，你可以失去1点体力，则此【杀】继续造成伤害。",
  ["#hx__luoyi_select"] = "请先选择发动技能后获得的基本牌、锦囊牌、装备牌各一张",
  ["#hx__luoyi_get"] = "是否获得这些牌",
  ["hx__luoyi_get"] = "获得",
  ["hx__luoyi_fou"] = "不获得",
  ["@@hx__luoyi"] = "裸衣",
  ["#hx__luoyi_delay"] = "裸衣",
  ["#hx__luoyi-ask"] = "裸衣：请选择一项",
  ["$hx__luoyi1"] = "反国之贼，敢与我战吗！",
  ["$hx__luoyi2"] = "区区马儿，待我斩他建功！",
  ["$hx__baoji1"] = "铿铿虎将，岂能为兵甲所累？！",
  ["$hx__baoji2"] = "定要与那马儿杀个酣畅淋漓！",
  ["~huixiangqy__mouxuchu"] = "主公，为何先仲康而去啊！",
}
Fk:addPoxiMethod{
  name = "hx__luoyi__type",
  card_filter = function(to_select, selected, data)
    if table.contains(data[2], to_select) then return true end
    local n = Fk:getCardById(to_select).type
    for _, id in ipairs(data[2]) do
      if Fk:getCardById(id).type == n then return false end
    end
    return true
  end,
  feasible = function(selected)
    return true
  end,
}
local hx__luoyi = fk.CreateTriggerSkill{
  name = "hx__luoyi",
  anim_type = "offensive",
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player.phase == Player.Draw
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local cids = room:getNCards(player.maxHp)
    room:moveCardTo(cids, Card.Processing, nil, fk.ReasonJustMove, self.name, nil, true, player.id)
    local function clearRemain(ids)
      ids = table.filter(ids, function(id) return room:getCardArea(id) == Card.Processing end)
      room:moveCardTo(ids, Card.DiscardPile, nil, fk.ReasonPutIntoDiscardPile, self.name, nil, true, player.id)
    end
    local cards = {}
    for _, id in ipairs(cids) do
      local card = Fk:getCardById(id)
      if card then
        table.insert(cards, id)
      end
    end
    if #cards > 0 then
      local get = room:askForArrangeCards(player, self.name, {cards},
      "#hx__luoyi_select", false, 0, {4, 4}, {0, 1}, ".", "hx__luoyi__type", {{}, {cards[1]}})[2]
      if #get == 0 then return end
      if #get > 0 and room:askForChoice(player, {"hx__luoyi_fou","hx__luoyi_get"}, "#hx__luoyi_get") == "hx__luoyi_get" then
        room:moveCardTo(get, Player.Hand, player, fk.ReasonJustMove, self.name, "", true, player.id)
        cards = table.filter(cards, function(id) return room:getCardArea(id) == Card.Processing end)
        room:moveCards({
          ids = cards,
          toArea = Card.DiscardPile,
          moveReason = fk.ReasonPutIntoDiscardPile,
        })
        if not player.dead then room:addPlayerMark(player, "@@hx__luoyi") end
        clearRemain(cids)
        return true
      end
    end
    clearRemain(cids)
  end,
  refresh_events = {fk.TurnStart},
  can_refresh = function(self, event, target, player, data)
    return target == player and player:getMark("@@hx__luoyi") ~= 0
  end,
  on_refresh = function(self, event, target, player, data)
    player.room:setPlayerMark(player, "@@hx__luoyi", 0)
  end,
}
local hx__luoyi_delay = fk.CreateTriggerSkill{
  name = "#hx__luoyi_delay",
  mute = true,
  events = {fk.DamageCaused},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:getMark("@@hx__luoyi") > 0 and
      data.card and (data.card.trueName == "slash" or data.card.name == "duel") and
      player.room.logic:damageByCardEffect()
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    player:broadcastSkillInvoke("hx__luoyi")
    data.damage = data.damage + 1
  end,
}

local hx__baoji = fk.CreateTriggerSkill{
  name = "hx__baoji",
  anim_type = "offensive",
  events = {fk.CardEffectCancelledOut},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and data.from == player.id and data.card.trueName == "slash" and
      not player.room:getPlayerById(data.to).dead
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:loseHp(player, 1, self.name)
    return true
  end,
}

huixiangqy__mouxuchu:addSkill(hx__luoyi)
hx__luoyi:addRelatedSkill(hx__luoyi_delay)
huixiangqy__mouxuchu:addSkill(hx__baoji)


Fk:loadTranslationTable{
  ["huixiangqy__mouganning"] = "谋甘宁",
  ["designer:huixiangqy__mouganning"] = "非电竞恐龙",
  ["hx__qixi"] = "奇袭",
  [":hx__qixi"] = "准备阶段开始时和自己回合结束阶段时，你获得1个“骑”标记，你至多拥有2个“骑”标记。出牌阶段时，你可以消耗1个“骑”标记选择一项：1.弃置任意名角色区域内共计至多两张牌；2.获得一名角色区域内的一张牌。",
  ["hx__fenwei"] = "奋威",
  [":hx__fenwei"] = "限定技，当一张非装备非延迟锦囊牌指定目标后，你可以令此牌对其中任意个目标无效并增加至多X个目标或令此牌额外结算Y次（X为场上存活人数，Y为你已损失的体力值）。" ..
  "<br><font color='gray'>注：无效的目标后续则不会再成为目标。</font>",
  ["@hx__qixi"] = "骑",
  ["#hx__qixi"] = "你可以消耗1个“骑”标记选择一项：1.弃置任意名角色区域内共计至多两张牌；2.获得一名角色区域内的一张牌。",
  ["#hx__qixi_delay"] = "奇袭",
  ["hx__qixi_discard"] = "弃置任意名角色区域内共计至多两张牌",
  ["hx__qixi_get"] = "获得一名角色区域内的一张牌",
  ["#hx__qixi_get_target"] = "请选择一名角色",
  ["#hx__qixi_card"] = "请选择一张牌",
  ["hx__fenwei_target"] = "先令此牌在本次结算中对其中任意个目标无效并增加至多X个目标（X为场上存活人数）",
  ["hx__fenwei_more"] = "令此牌额外结算Y次（Y为你已损失的体力值）",
  ["#hx__fenwei-choose-remove"] = "奋威：请选择无效的目标",
  ["#hx__fenwei-choose"] = "奋威：你可以为此牌增加至多X个目标（X为场上存活人数）",
  ["$hx__qixi1"] = "胆敢进犯之敌，都杀他个措手不及。",
  ["$hx__qixi2"] = "东吴的地盘，来者都是有去无回！",
  ["$hx__fenwei1"] = "若是折损一兵一将，都不算我有功！",
  ["$hx__fenwei2"] = "百骑破敌，则百骑皆回。",
  ["~huixiangqy__mouganning"] = "主恩既报，兴霸死而无憾了。",
}

local hx__qixi_delay = fk.CreateTriggerSkill{
  name = "#hx__qixi_delay",
  anim_type = "masochism",
  frequency = Skill.Compulsory,
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) then
      if player.phase == Player.Finish or player.phase == Player.Start then
        return true
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if player:getMark("@hx__qixi") < 2 then
      player:broadcastSkillInvoke("hx__qixi")
      room:addPlayerMark(player, "@hx__qixi", 1)
    end
  end,
}
local hx__qixi = fk.CreateActiveSkill{
  name = "hx__qixi",
  anim_type = "offensive",
  prompt = "#hx__qixi",
  can_use = function(self, player)
    return player:getMark("@hx__qixi") > 0
  end,
  card_num = 0,
  card_filter = function() return false end,
  target_num = 0,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local choice = room:askForChoice(player, {"hx__qixi_discard","hx__qixi_get"},self.name)
    room:removePlayerMark(player, "@hx__qixi", 1)
    if choice == "hx__qixi_get" then
      local targets = room:askForChoosePlayers(player, table.map(room.alive_players, Util.IdMapper), 1, 1, "#hx__qixi_get_target", self.name, false)
      if room:getPlayerById(targets[1]):isAllNude() then return end
      if #targets > 0 then
        local card = {room:askForCardChosen(player, room:getPlayerById(targets[1]), "hej", self.name, "#hx__qixi_card")}
        room:moveCardTo(card, Player.Hand, player, fk.ReasonJustMove, self.name, "", true, player.id)
      end
    elseif choice == "hx__qixi_discard" then
      local tar1 = room:askForChoosePlayers(player, table.map(room.alive_players,Util.IdMapper), 1, 1, "#hx__qixi_get_target", self.name, true)
      if room:getPlayerById(tar1[1]):isAllNude() then return end
      if #tar1 > 0 then
        local id1 = room:askForCardChosen(player, room:getPlayerById(tar1[1]), "hej", self.name, "#hx__qixi_card")
        room:throwCard({id1}, self.name, room:getPlayerById(tar1[1]), player)
      end
      local tar2 = room:askForChoosePlayers(player, table.map(room.alive_players, Util.IdMapper), 1, 1, "#hx__qixi_get_target", self.name, true)
      if room:getPlayerById(tar2[1]):isAllNude() then return end
      if #tar2 > 0 then
        local id2 = room:askForCardChosen(player, room:getPlayerById(tar2[1]), "hej", self.name, "#hx__qixi_card")
        room:throwCard({id2}, self.name, room:getPlayerById(tar2[1]), player)
      end
    end
  end,
}

local hx__fenwei = fk.CreateTriggerSkill{
  name = "hx__fenwei",
  frequency = Skill.Limited,
  events = {fk.TargetSpecified},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) and data.firstTarget and (data.card.type == Card.TypeBasic or data.card:isCommonTrick()) then
      return player:usedSkillTimes(self.name, Player.HistoryGame) == 0
    end
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askForSkillInvoke(player, self.name)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local choice = {"hx__fenwei_target", "hx__fenwei_more"}
    local choose = room:askForChoice(player, choice, self.name)
    local x = #room:getAlivePlayers()
    local y = player.maxHp - player.hp
    if choose == "hx__fenwei_target" then
      local candidates = table.filter(room:getAlivePlayers(), function(p)
        return not p.dead and not table.contains(AimGroup:getAllTargets(data.tos), p.id)
      end)
      local tos = player.room:askForChoosePlayers(player, AimGroup:getAllTargets(data.tos), 1, 999,
      "#hx__fenwei-choose-remove:::"..data.card:toLogString(), self.name, true)
      table.insertTable(data.nullifiedTargets, tos)
      local newTargets = room:askForChoosePlayers(player, table.map(candidates, Util.IdMapper), 0, x, "#hx__fenwei-choose", self.name, true)
      if #newTargets > 0 then
        for _, id in ipairs(newTargets) do
          TargetGroup:pushTargets(data.targetGroup, {id})
        end
      end
    elseif choose == "hx__fenwei_more" then
      data.additionalEffect = (data.additionalEffect or 0) + y
    end
  end,
}

huixiangqy__mouganning:addSkill(hx__qixi)
hx__qixi:addRelatedSkill(hx__qixi_delay)
huixiangqy__mouganning:addSkill(hx__fenwei)


Fk:loadTranslationTable{
  ["huixiangqy__moudianwei"] = "谋典韦",
  ["designer:huixiangqy__moudianwei"] = "非电竞恐龙",
  ["hx__qiangxi"] = "强袭", 
  [":hx__qiangxi"] = "转换技，出牌阶段限一次，你可以失去1点体力并弃置一张装备牌，阳：依次对攻击范围内两名其他角色各造成1点伤害；阴：对攻击范围内的一名其他角色造成2点伤害。",
  ["hx__yuzhan"] = "愈战",
  [":hx__yuzhan"] = "当你使用【杀】或【决斗】造成伤害后，你可以选择一项：1.回复一点体力；2.从牌堆或弃牌堆中获得一张装备牌；背水：废除自己一个装备栏。",
  ["#hx__yuanzhan-ask"] = "请选择一个装备栏废除。",
  ["#hx__qiangxi-yang"] = "你可以失去1点体力或弃置一张装备牌，对攻击范围内一名其他角色造成1点伤害。",
  ["#hx__qiangxi-yang-choose"] = "你可以选择另一名其他角色也对其造成1点伤害。",
  ["#hx__qiangxi-yin"] = "你可以失去1点体力并弃置一张装备牌，对攻击范围内的一名其他角色造成2点伤害。",
  ["hx__yuzhan_recover"] = "回复一点体力",
  ["hx__yuzhan_get"] = "从牌堆或弃牌堆中获得一张装备牌",
  ["hx__yuzhan_all"] = "背水",
  ["$hx__qiangxi1"] = "耶啊！谁还敢往前半步！",
  ["$hx__qiangxi2"] = "双戟一出，何人能敌！",
  ["$hx__yuzhan1"] = "人戟合一，所向披靡！",
  ["$hx__yuzhan2"] = "牵马拿戟，待我迎阵！",
  ["~huixiangqy__moudianwei"] = "欲伤吾主，就先从我的尸体上踏过去！",
}

local hx__qiangxi = fk.CreateActiveSkill{
  name = "hx__qiangxi",
  anim_type = "switch",
  switch_skill_name = "hx__qiangxi",
  can_use = function(self, player)
    local equipCards = table.filter(Self:getCardIds("he"), function(id)
      return Fk:getCardById(id).type == Card.TypeEquip 
    end)
    return player.phase == Player.Play and #equipCards > 0 and player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  card_num = 1,
  target_num = 1,
  target_filter = function(self, to_select, selected, selected_cards)
    if Self:getSwitchSkillState(self.name, false) == fk.SwitchYang then
      if #selected == 0 and to_select ~= Self.id then
        if #selected_cards == 0 or table.contains(Self:getCardIds("he"), selected_cards[1]) then
          return Self:inMyAttackRange(Fk:currentRoom():getPlayerById(to_select))
        else
          return Self:distanceTo(Fk:currentRoom():getPlayerById(to_select)) == 1
        end
      end
    else
      if #selected == 0 and to_select ~= Self.id then
        if #selected_cards == 0 or table.contains(Self:getCardIds("he"), selected_cards[1]) then
          return Self:inMyAttackRange(Fk:currentRoom():getPlayerById(to_select))
        else
          return Self:distanceTo(Fk:currentRoom():getPlayerById(to_select)) == 1
        end
      end
    end
  end,
  prompt = function(self, selected, selected_cards)
		if Self:getSwitchSkillState(self.name, false) == fk.SwitchYang then
      return "#hx__qiangxi-yang"
    else
      return "#hx__qiangxi-yin"
    end
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.tos[1])
    if player:getSwitchSkillState(self.name, true) == fk.SwitchYang then
      local another = table.filter(room:getOtherPlayers(player), function(p) return p ~= target end)
      room:addTableMark(player, "hx__qiangxi_yang-phase", target.id)
      if #effect.cards > 0 then
        room:loseHp(player, 1, self.name)
        room:throwCard(effect.cards, self.name, player)
        room:damage{
          from = player,
          to = target,
          damage = 1,
          skillName = self.name,
        }
        if #another > 0 then
          local target2 = room:askForChoosePlayers(player, table.map(another, Util.IdMapper), 1, 1, "#hx__qiangxi-yang-choose", self.name, false)
          if #target2 > 0 then
            room:damage{
              from = player,
              to = room:getPlayerById(target2[1]),
              damage = 1,
              skillName = self.name,
            }
          end
        end
      end
    else
      if #effect.cards > 0 then
        room:addTableMark(player, "hx__qiangxi_yin-phase", target.id)
        room:loseHp(player, 1, self.name)
        room:throwCard(effect.cards, self.name, player)
        room:damage{
          from = player,
          to = target,
          damage = 2,
          skillName = self.name,
        }
      end
    end
  end,
}

local hx__yuzhan = fk.CreateTriggerSkill{
  name = "hx__yuzhan",
  anim_type = "offensive",
  events = {fk.Damage},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and data.card and ( data.card.trueName == "slash" or data.card.trueName == "duel")
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local choice = {"hx__yuzhan_recover", "hx__yuzhan_get"}
    local choices = player:getAvailableEquipSlots()
    if #choices > 0 then 
      table.insert(choice, "hx__yuzhan_all")
    end
    local choose = room:askForChoice(player, choice, self.name)
    if choose == "hx__yuzhan_recover" or choose == "hx__yuzhan_all" then
      room:recover({
        who = player,
        num = 1,
        recoverBy = player,
        skillName = self.name
      })
    end
    if choose == "hx__yuzhan_get" or choose == "hx__yuzhan_all" then
      local card = room:getCardsFromPileByRule(".|.|.|.|.|equip", 1, "allPiles")
      if #card > 0 then
        room:moveCards({
          ids = card,
          to = player.id,
          toArea = Card.PlayerHand,
          moveReason = fk.ReasonJustMove,
          proposer = player.id,
          skillName = self.name,
        })
      end
    end
    if choose == "hx__yuzhan_all" then
      local choice = room:askForChoice(player, choices, self.name, "#hx__yuzhan-ask")
      room:abortPlayerArea(player, choice)
    end
  end,
  
}
huixiangqy__moudianwei:addSkill(hx__qiangxi)
huixiangqy__moudianwei:addSkill(hx__yuzhan)



Fk:loadTranslationTable{
  ["huixiangqy__shimachao"] = "势马超",
  ["designer:huixiangqy__shimachao"] = "非电竞恐龙",
  ["hx__shizhan"] = "誓战",
  [":hx__shizhan"] = "转换技，出牌阶段限一次，阳：失去1点体力并依次弃置其他角色两张牌；阴：回复1点体力并摸两张牌。若如此做，你摸X张牌（X为你已损失的体力值），且你本回合使用【杀】的次数上限为Y（Y为你的当前体力值）。",
  ["hx__xicao"] = "袭曹",
  [":hx__xicao"] = "锁定技，当你的已损失体力值大于当前体力值时，你使用的【杀】伤害+1且不可响应；当你的当前体力值大于已损失体力值时，你使用的【决斗】伤害+1且不可响应。" ,
  ["#hx__shizhan-yang"] = "失去1点体力并依次弃置其他角色两张牌",
  ["#hx__shizhan-yin"] = "回复1点体力并摸两张牌。",
  ["#hx__shizhan-choose"] = "请选择一名其他角色弃置其一张牌",
  ["#hx__shizhan-card1"] = "请选择第一张要弃置的牌",
  ["#hx__shizhan-card2"] = "请选择第二张要弃置的牌",
  ["@hx__shizhan"] = "杀上限",
  ["$hx__shizhan1"] = "冬至天寒，敌必疲软，正可奇袭以退！",
  ["$hx__shizhan2"] = "纵使敌酋如何防备，也难阻我马家雄师！",
  ["$hx__xicao1"] = "听我号令，骑兵尽出，袭杀曹贼！",
  ["$hx__xicao2"] = "铁枪横扫之处，尔等断无残生之机！",
  ["~huixiangqy__shimachao"] = "血仇无报，坎坷一生，哎……",
}

local hx__shizhan = fk.CreateActiveSkill{
  name = "hx__shizhan",
  anim_type = "switch",
  switch_skill_name = "hx__shizhan",
  can_use = function(self, player)
    return player.phase == Player.Play and player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  card_num = 0,
  target_filter = function(self, to_select, selected)
    if Self:getSwitchSkillState(self.name, false) == fk.SwitchYang then
      return #selected == 0 and to_select ~= Self.id
    else
      return #selected == 0 and to_select == Self.id
    end
  end,
  target_num = 1,
  prompt = function(self, selected, selected_cards)
		if Self:getSwitchSkillState(self.name, false) == fk.SwitchYang then
      return "#hx__shizhan-yang"
    else
      return "#hx__shizhan-yin"
    end
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.tos[1])
    if player:getSwitchSkillState(self.name, true) == fk.SwitchYang then
      room:loseHp(player, 1, self.name)
      if player.dead then return end
      if target:isNude() then return end
      local id1 = room:askForCardsChosen(player, target, 1, 1, "he","#hx__shizhan-card1")
      room:throwCard({id1}, self.name, target, player)
      local target2 = room:askForChoosePlayers(player, table.map(room:getOtherPlayers(player), Util.IdMapper), 1, 1, "#hx__shizhan-choose", self.name, true)
      if room:getPlayerById(target2[1]):isNude() or #target2 == 0 then return end
      local id2 = room:askForCardsChosen(player, room:getPlayerById(target2[1]), 1, 1, "he","#hx__shizhan-card2")
      room:throwCard({id2}, self.name, room:getPlayerById(target2[1]), player)
    else
      room:recover({
        who = player,
        num = 1,
        recoverBy = player,
        skillName = self.name
      })
      player:drawCards(2, self.name)
    end
    local x = player.maxHp - player.hp
    local y = player.hp
     player:drawCards(x, self.name)
     room:addPlayerMark(player, "@hx__shizhan", y)
  end,
}

local hx__shizhan_remove = fk.CreateTriggerSkill{
  name = "#hx__shizhan_remove",
  mute = true,
  frequency = Skill.Compulsory,
  events = {fk.TurnEnd},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and target == player and player:getMark("@hx__shizhan") > 0
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:setPlayerMark(player, "@hx__shizhan", 0)
  end,
}
local hx__shizhan_mod = fk.CreateTargetModSkill{
  name = "#hx__shizhan_mod",
  residue_func = function(self, player, skill, scope)
    if skill.trueName == "slash_skill" and scope == Player.HistoryPhase and player.phase == Player.Play and player:getMark("@hx__shizhan") > 0 then
      return player:getMark("@hx__shizhan") - 1
    end
    return 0
  end,
}

local hx__xicao = fk.CreateTriggerSkill{
  name = "hx__xicao",
  anim_type = "offensive",
  frequency = Skill.Compulsory,
  events = {fk.TargetSpecified},
  can_trigger = function(self, event, target, player, data)
    local x = player.maxHp - player.hp
    local y = player.hp
    if x > y then
    return target == player and player:hasSkill(self) and  data.card.trueName == "slash"
    elseif x < y then
      return target == player and player:hasSkill(self) and  data.card.trueName == "duel"
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    data.additionalDamage = (data.additionalDamage or 0) + 1
    data.disresponsive = true
  end,
}


huixiangqy__shimachao:addSkill(hx__shizhan)
hx__shizhan:addRelatedSkill(hx__shizhan_remove)
hx__shizhan:addRelatedSkill(hx__shizhan_mod)
huixiangqy__shimachao:addSkill(hx__xicao)

Fk:loadTranslationTable{
  ["huixiangqy__spzhouyu"] = "SP周瑜",
  ["designer:huixiangqy__spzhouyu"] = "非电竞恐龙/庆思书",
  ["hx__junju"] = "俊举",
  ["#hx__junju_change"] = "俊举",
  [":hx__junju"] = "锁定技，游戏开始时，你从牌堆中获得两张牌，你摸牌时改为从弃牌堆中获得等量的牌（不够则仅获得剩余的牌）。你的手牌始终置于武将牌上。你可以如手牌般使用或打出你武将牌上的牌。",
  ["hx__lanyue"] = "览乐",
  [":hx__lanyue"] = "每轮限四次，当有牌因弃置而进入弃牌堆时，你可以获得这些牌或从弃牌堆中随机获得X张牌（不够则仅获得剩余的牌），若如此做，当前回合角色手牌上限-X直到你下次发动此技能（X为弃置的牌数）。",
  ["@@hx__lanyue_effect"] = "<font color='#FF0006'>已览乐</font>",
  ["@hx__lanyue"] = "手牌上限-",
  ["hx__junju&"] = "<font color='#FF0011'>俊举</font>",
  ["#hx__lanyue-get"] = "获得这些牌",
  ["#hx__lanyue-find"] = "从弃牌堆中随机获得X张牌（X为弃置的牌数）",
  ["$hx__junju1"] = "天下虽英雄如云，我周公瑾可胜者十之八九。",
  ["$hx__junju2"] = "此敌中做敌之计，倒看汝如何破解？",
  ["$hx__lanyue1"] = "登临荆山麓，纵酒莫负春！",
  ["$hx__lanyue2"] = "莲开漾碧水，风暖动心弦。",
  ["~huixiangqy__spzhouyu"] = "吾虽将陨，自忖未愧伯符之托，无憾矣……",
}
local hx__junju = fk.CreateTriggerSkill{
  name = "hx__junju",
  anim_type = "control",
  frequency = Skill.Compulsory,
  events = {fk.AfterCardsMove,fk.GameStart},
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(self) or #player:getCardIds("h") == 0 then return false end
    local cards = {}
    if event == fk.AfterCardsMove then
      table.insertIfNeed(cards, player:getCardIds("h"))
      cards = U.moveCardsHoldingAreaCheck(player.room, cards)
      if #cards > 0 then
        self.cost_data = cards
        return true
      end
    elseif event == fk.GameStart then
      local cards2 = player:getCardIds(Player.Hand)
      if #cards2 > 0 then
        self.cost_data = cards2
        return true
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local cards = self.cost_data
    if event == fk.GameStart then
      local ids = room:getCardsFromPileByRule(".|.|.", 2, "drawPile")
      if #ids > 0 then
        room:moveCards({
          ids = ids,
          to = player.id,
          toArea = Card.PlayerHand,
          moveReason = fk.ReasonJustMove,
          proposer = player.id,
          skillName = self.name,
        })
      end
    end
    player:addToPile("hx__junju&", cards, false, self.name, player.id,nil)
  end,
}

local hx__junju_change = fk.CreateTriggerSkill {
  name = "#hx__junju_change",
  events = {fk.BeforeDrawCard},
  anim_type = "negative",
  frequency = Skill.Compulsory,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local num = data.num
    local discard = #room.discard_pile
    if discard >= num then
      data.num = 0
      local ids = room:getCardsFromPileByRule(".|.|.", num, "discardPile")
      if #ids > 0 then
        room:moveCards({
          ids = ids,
          to = player.id,
          toArea = Card.PlayerHand,
          moveReason = fk.ReasonJustMove,
          proposer = player.id,
          skillName = self.name,
        })
      end
    else
      data.num = 0
      local ids = room:getCardsFromPileByRule(".|.|.", discard, "discardPile")
      if #ids > 0 then
        room:moveCards({
          ids = ids,
          to = player.id,
          toArea = Card.PlayerHand,
          moveReason = fk.ReasonJustMove,
          proposer = player.id,
          skillName = self.name,
        })
      end
    end
  end,
}

local hx__lanyue = fk.CreateTriggerSkill {
  name = "hx__lanyue",
  anim_type = "drawcard",
  events = {fk.AfterCardsMove },
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(self) then return end
    if event == fk.AfterCardsMove and player:usedSkillTimes(self.name, Player.HistoryRound) < 4 then
      local cards = {}
      local room = player.room
      for _, move in ipairs(data) do
        if move.moveReason == fk.ReasonDiscard and move.toArea == Card.DiscardPile then
          for _, info in ipairs(move.moveInfo) do
            if info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerEquip and room:getCardArea(info.cardId) == Card.DiscardPile then
              table.insertIfNeed(cards, info.cardId)
            end
          end
        end
      end
      cards = U.moveCardsHoldingAreaCheck(room, cards)
      if #cards > 0 then
        self.cost_data = cards
        return true
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local num = #self.cost_data
    room:addPlayerMark(player, "@@hx__lanyue_effect")
    local tos = table.filter(room:getAlivePlayers(), function(p) return p:getMark("@hx__lanyue") > 0 end)
    if #tos > 0 then
      local n = tos[1]:getMark("@hx__lanyue")
      room:removePlayerMark(tos[1], "@hx__lanyue", n)
      room:removePlayerMark(tos[1], MarkEnum.MinusMaxCards, n)
    end
    local choices = {"#hx__lanyue-get"}
    if #room.discard_pile > 0 then
      table.insert(choices, "#hx__lanyue-find")
      if #room.discard_pile < num then
        num = #room.discard_pile
      end
    end
    local choice = room:askForChoice(player, choices, self.name)
    if choice == "#hx__lanyue-get" then
      room:moveCardTo(self.cost_data, Card.PlayerHand, player, fk.ReasonJustMove, self.name, nil, true, player.id)
    elseif choice == "#hx__lanyue-find" then
      local ids = room:getCardsFromPileByRule(".|.|.", num, "discardPile")
      if #ids > 0 then
        room:moveCards({
          ids = ids,
          to = player.id,
          toArea = Card.PlayerHand,
          moveReason = fk.ReasonJustMove,
          proposer = player.id,
          skillName = self.name,
        })
      end
    end
    local turn_event = player.room.logic:getCurrentEvent():findParent(GameEvent.Turn)
		if turn_event == nil then return end
		local to = turn_event.data[1]
    room:addPlayerMark(to, "@hx__lanyue", num)
    room:addPlayerMark(to, MarkEnum.MinusMaxCards, num)
  end,
}

huixiangqy__spzhouyu:addSkill(hx__junju)
hx__junju:addRelatedSkill(hx__junju_change)
huixiangqy__spzhouyu:addSkill(hx__lanyue)

Fk:loadTranslationTable{
  ["huixiangqy__mouliushan"] = "谋刘禅",
  ["designer:huixiangqy__mouliushan"] = "非电竞恐龙",
  ["hx__xiangle"] = "享乐",
  [":hx__xiangle"] = "当一名角色回复体力后（每回合限一次）或脱离濒死状态时，你获得4个“愚”标记（你至多拥有10个“愚”标记）。出牌阶段限一次，你可以选择一名角色，移去任意数量的“愚”令其获得对应的一个效果:2个，当该角色成为其他角色使用【杀】的目标时其他角色需要弃置一张基本牌否则此【杀】无效；3个，当该角色成为其他角色使用【杀】的目标时其他角色需要弃置一张锦囊牌否则此【杀】无效；4个，当该角色成为其他角色使用【杀】的目标时其他角色需要弃置一张装备牌否则此【杀】无效。",
  ["hx__fangquan"] = "放权",
  [":hx__fangquan"] = "出牌阶段限一次，若你有“享乐”，你可以选择一名其他角色，移去任意数量的“愚”令其获得对应的一个效果：2个，其本轮摸牌阶段多摸两张牌；4个，其本轮跳过弃牌阶段；6个，其本轮使用【杀】伤害＋1，或其本轮使用【杀】可以结算两次；8个，在你的当前回合结束后其获得一个额外的回合，或可以回复2点体力值。",
  ["hx__ruoyu"] = "若愚",
  [":hx__ruoyu"] = "主公技，出牌阶段开始时，若你有“享乐”，你获得X个“愚”标记（X为本局游戏其他蜀势力角色数的两倍）。每局限一次，出牌阶段，你可以令一名其他蜀势力角色将体力值回复至体力上限并将手牌也摸至体力上限。",

}


Fk:loadTranslationTable{
  ["huixiangqy__liuchen"] = "刘谌",
  ["designer:huixiangqy__liuchen"] = "非电竞恐龙",
  ["hx__zhanjue"] = "战绝",
  [":hx__zhanjue"] = "失恒技。游戏开始时，你获得20点战意值。如下情况时，你对应获得一定数量的“战意”值：1.你受到1点伤害后一一10点；2.你造成1点伤害后一一15点；3.你获得牌时一一5点。你根据战意值视为拥有如下技能：25点-“振鞘”；50点-“仁德”；75点-“放权”；100点-“言战”。你的战意值上限为100。",
  ["hx__kangxiang"] = "抗降",
  [":hx__kangxiang"] = "失恒技。主公技。游戏开始时，若场上有其他蜀势力角色且你拥有“战绝”，则你因“战绝”于游戏开始时获得的战意值修改为60点。",
--振鞘，你的攻击范围＋1。每轮限一次，当你使用【杀】指定目标后，你可以令此【杀】的结算执行两次。
--仁德，每轮开始时，你获得一个“仁望”标记，你的回合外，当你需要使用一张【桃】时，你可以弃置一个“仁望”标记视为使用，每轮结束时，你失去一个“仁望”标记 。
--放权，准备阶段开始时，你可以选择一项令一名角色获得（不能选择上个出牌阶段选择的角色）：1.其本轮摸牌阶段开始时，多摸两张牌；2.其本轮出牌阶段结束时，跳过弃牌阶段。
--言战，限定技。出牌阶段，你可令所有角色将体力值改为1点获得X点护甲，你多获得2点护甲（X以此法减少的体力值），令场上获得“向死存蜀”光环效果:令所有玩家的【闪】【桃】【酒】只能当【决斗】使用。
}


Fk:loadTranslationTable{
  ["huixiangqy__shenxusheng"] = "神徐盛",
  ["designer:huixiangqy__shenxusheng"] = "非电竞恐龙",
  ["hx__yicheng"] = "疑城",
  [":hx__yicheng"] = "锁定技，每轮每名角色限一次，当你使用【杀】指定目标后，你令目标角色选择一项：1.其交给你所有牌，此回合结束后其摸X张牌（X为其以此法失去的牌数）；2.其失去2点体力弃置所有牌令此【杀】无效。",
  ["hx__kuijun"] = "溃军",
  ["#hx__kuijun_card"] = "溃军",
  ["#hx__kuijun_attackrange"] = "溃军",
  ["#hx__kuijun_chusha"] = "溃军",
  [":hx__kuijun"] = "锁定技，你的【桃】视为【酒】，你的【酒】视为【桃】，你的攻击范围＋3，当你使用【杀】指定目标后，若目标角色的牌少于你，你选择一项:1.此【杀】伤害+1；2.此【杀】额外结算一次；3.此【杀】结算后增加一次出杀次数；4.此【杀】结算后回收此牌。",
  ["#hx__yicheng1"] = "交给神徐盛所有牌，此回合结束后你摸X张牌（X为你以此法失去的牌数）",
  ["#hx__yicheng2"] = "失去2点体力并弃置所有牌，令此【杀】无效",
  ["@hx__yicheng_draw"] = "疑城摸牌数",
  ["@@hx__yicheng-round"] = "已疑城",
  ["#hx__kuijun_damage"] = "此【杀】伤害+1",
  ["#hx__kuijun_extra"] = "此【杀】额外结算一次",
  ["#hx__kuijun_slash"] = "此【杀】结算后增加一次出杀次数",
  ["#hx__kuijun_get"] = "此【杀】结算后回收此牌",
  ["@hx__kuijun_slash"] = "出杀次数+",
  ["$hx__yicheng1"] = "魏虽武骑千群，临江亦无所用!",
  ["$hx__yicheng2"] = "我自岿然江东镇，霸涛怒海功业存!",
  ["$hx__kuijun1"] = "横刀长江畔，贼子安敢前！",
  ["$hx__kuijun2"] = "敌军卸甲怠备，待盛直捣黄龙！",
  ["~huixiangqy__shenxusheng"] = "来日长江激湍阻敌，或是盛忠魂所化……",
  ["$huixiangqy__shenxusheng_win_audio"] = "广陵百里疑城在，不教片帆过江来！",
}
local huixiangqy__shenxushengwin = fk.CreateActiveSkill{ name = "huixiangqy__shenxusheng_win_audio" }
huixiangqy__shenxushengwin.package = extension
Fk:addSkill(huixiangqy__shenxushengwin)

local hx__yicheng = fk.CreateTriggerSkill{
  name = "hx__yicheng",
  anim_type = "offensive",
  frequency = Skill.Compulsory,
  events = {fk.TargetSpecified},
  can_trigger = function(self, event, target, player, data)
    local to = player.room:getPlayerById(data.to)
    return target == player and player:hasSkill(self) and data.card.trueName == "slash" and to:getMark("@@hx__yicheng-round") == 0
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(data.to)
    local card = to:getCardIds{Player.Hand, Player.Equip}
    local choices = {"#hx__yicheng1","#hx__yicheng2"}
    local choice = room:askForChoice( to, choices, self.name)
    room:addPlayerMark(to, "@@hx__yicheng-round")
    if choice == "#hx__yicheng1" then
      if #card == 0 then return end
      room:obtainCard(player, card, false, fk.ReasonGive, to.id)
      room:addPlayerMark(to, "@hx__yicheng_draw", #card)
    else
      to:throwAllCards("he", self.name)
      room:loseHp(to, 2, self.name)
      data.nullifiedTargets = AimGroup:getAllTargets(data.tos)
    end
  end,
} 
local hx__yicheng_draw = fk.CreateTriggerSkill{
  name = "#hx__yicheng_draw",
  mute = true,
  frequency = Skill.Compulsory,
  events = {fk.TurnEnd},
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(self) then return end
    local tos = table.filter(player.room:getAlivePlayers(), function(p) return p:getMark("@hx__yicheng_draw") > 0 end)
    return #tos > 0
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local tos = table.filter(player.room:getAlivePlayers(), function(p) return p:getMark("@hx__yicheng_draw") > 0 end)
    if #tos > 0 then
      for _, p in ipairs(tos) do
        room:drawCards(p, p:getMark("@hx__yicheng_draw"), self.name)
        room:setPlayerMark(p, "@hx__yicheng_draw", 0)
      end
    end
  end,
}

local hx__kuijun = fk.CreateTriggerSkill{
  name = "hx__kuijun",
  anim_type = "offensive",
  frequency = Skill.Compulsory,
  events = {fk.TargetSpecified},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self) and data.card and data.card.trueName == "slash" then
      if event == fk.TargetSpecified then
        local to = player.room:getPlayerById(data.to)
        return not to.dead and #player:getCardIds{Player.Hand, Player.Equip} > #to:getCardIds{Player.Hand, Player.Equip}
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(data.to)
    local choices = {"#hx__kuijun_damage", "#hx__kuijun_extra", "#hx__kuijun_slash", "#hx__kuijun_get"}
    local choice = room:askForChoice(player, choices, self.name)
    if choice == "#hx__kuijun_damage" then
      data.additionalDamage = (data.additionalDamage or 0) + 1
      room:sendLog{
        type = "神徐盛选择了此【杀】伤害+1",
        from = player.id,
        arg = self.name
      }
    elseif choice == "#hx__kuijun_extra" then
      data.additionalEffect = (data.additionalEffect or 0) + 1
      room:sendLog{
        type = "神徐盛选择了此【杀】额外结算一次",
        from = player.id,
        arg = self.name
      }
    elseif choice == "#hx__kuijun_slash" then
      room:addPlayerMark(player, "@hx__kuijun_slash", 1)
      room:sendLog{
        type = "神徐盛选择了此【杀】结算后增加一次出杀次数",
        from = player.id,
        arg = self.name
      }
    elseif choice == "#hx__kuijun_get" then
      room:obtainCard(player, data.card.id, true, fk.ReasonGive)
      room:sendLog{
        type = "神徐盛选择了此【杀】结算后回收此牌",
        from = player.id,
        arg = self.name
      }
    end
  end,
}

local hx__kuijun_chusha = fk.CreateTargetModSkill{
  name = "#hx__kuijun_chusha",
  residue_func = function(self, player, skill, scope, card)
    if player:hasSkill("hx__kuijun") and skill.trueName == "slash_skill" and scope == Player.HistoryPhase then
      return player:getMark("@hx__kuijun_slash")
    end
    return 0
  end,
}

local hx__kuijun_card = fk.CreateFilterSkill {
  name = "#hx__kuijun_card",
  card_filter = function(self, card, player)
      return player:hasSkill(self.name) and (card.name == "peach" or card.name == "analeptic")
  end,
  view_as = function(self, card, player)
    if card.name == "peach" then
      local c = Fk:cloneCard("analeptic")
      c:addSubcard(card)
      return c
    elseif card.name == "analeptic" then
      local c = Fk:cloneCard("peach")
      c:addSubcard(card)
      return c
    end
  end
}

local hx__kuijun_attackrange = fk.CreateAttackRangeSkill{
  name = "#hx__kuijun_attackrange",
  frequency = Skill.Compulsory,
  main_skill = hx__kuijun,
  correct_func = function (self, from, to)
    if from:hasSkill(hx__kuijun) then
      return 3
    end
    return 0
  end,
}


huixiangqy__shenxusheng:addSkill(hx__yicheng)
hx__yicheng:addRelatedSkill(hx__yicheng_draw)
huixiangqy__shenxusheng:addSkill(hx__kuijun)
hx__kuijun:addRelatedSkill(hx__kuijun_chusha)
hx__kuijun:addRelatedSkill(hx__kuijun_card)
hx__kuijun:addRelatedSkill(hx__kuijun_attackrange)

Fk:loadTranslationTable{
  ["hx__shihuai"] = "释怀",
  [":hx__shihuai"] = "锁定技，你的攻击范围+0，你使用【杀】无次数限制。",
  ["$hx__shihuai"] = "诸葛连弩声~~~",
}
local hx__shihuaiAudio = fk.CreateTriggerSkill{
  name = "#hx__shihuaiAudio",
  visible = false,
  refresh_events = {fk.CardUsing},
  can_refresh = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and
      data.card.trueName == "slash" and
      player:usedCardTimes("slash", Player.HistoryPhase) > 1
  end,
  on_refresh = function(self, event, target, player, data)
    player:broadcastSkillInvoke("hx__shihuai")
    player.room:doAnimate("InvokeSkill", {
      name = "hx__shihuai",
      player = player.id,
      skill_type = "offensive",
    })
  end,
}
local hx__shihuai = fk.CreateTargetModSkill{
  name = "hx__shihuai",
  frequency = Skill.Compulsory,
  bypass_times = function(self, player, skill, scope)
    if player:hasSkill(self) and skill.trueName == "slash_skill"
      and scope == Player.HistoryPhase then
      return true
    end
  end,
}
hx__shihuai:addRelatedSkill(hx__shihuaiAudio)

local hx__jianying = fk.CreateViewAsSkill{
  name = "hx__jianying",
  prompt = "#hx__jianying-active",
  interaction = function(self, player)
    local all_names = U.getAllCardNames("b")
    return U.CardNameBox {
      choices = U.getViewAsCardNames(player, self.name, all_names),
      all_choices = all_names,
      default_choice = "AskForCardsChosen",
    }
  end,
  handly_pile = true,
  card_filter = function(self, to_select, selected)
    return #selected == 0 and Fk.all_card_types[self.interaction.data] ~= nil
  end,
  view_as = function(self, cards, player)
    if Fk.all_card_types[self.interaction.data] == nil or #cards ~= 1 then return end
    local card = Fk:cloneCard(self.interaction.data)
    card:addSubcards(cards)
    local suitstrings = {"spade", "heart", "club", "diamond"}
    local suits = {Card.Spade, Card.Heart, Card.Club, Card.Diamond}
    local colors = {Card.Black, Card.Red, Card.Black, Card.Diamond}
    local suit = player:getMark("hx__jianying_suit-phase")
    if table.contains(suitstrings, suit) then
      card.suit = suits[table.indexOf(suitstrings, suit)]
      card.color = colors[table.indexOf(suitstrings, suit)]
    end

    card.skillName = self.name
    return card
  end,
  before_use = function(self, player, use)
    player.room:setPlayerMark(player, "hx__jianying_used-phase", 1)
  end,
  enabled_at_play = function(self, player)
    return player:getMark("hx__jianying_used-phase") == 0
  end,

  on_lose = function (self, player)
    local room = player.room
    room:setPlayerMark(player, "hx__jianying_used-phase", 0)
    room:setPlayerMark(player, "hx__jianying_suit-phase", 0)
    room:setPlayerMark(player, "hx__jianying_number-phase", 0)
    room:setPlayerMark(player, "@hx__jianying_record-phase", 0)
  end,
}
local hx__jianying_trigger = fk.CreateTriggerSkill{
  name = "#hx__jianying_trigger",
  events = {fk.CardUsing},
  mute = true,
  main_skill = hx__jianying,
  can_trigger = function(self, event, target, player, data)
    return data.from == player.id and player:hasSkill(hx__jianying) and player.phase == Player.Play and
      (data.extra_data or {}).hx__jianying_triggerable
  end,
  on_use = function(self, event, target, player, data)
    player:broadcastSkillInvoke(hx__jianying.name)
    player.room:notifySkillInvoked(player, hx__jianying.name, "drawcard")
    player:drawCards(1, hx__jianying.name)
  end,

  refresh_events = {fk.AfterCardUseDeclared},
  can_refresh = function(self, event, target, player, data)
    return target == player and player:hasSkill(hx__jianying, true) and player.phase == Player.Play
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    if data.card:getSuitString() == player:getMark("hx__jianying_suit-phase") or
        (data.card.number == player:getMark("hx__jianying_number-phase") and data.card.number ~= 0) then
      data.extra_data = data.extra_data or {}
      data.extra_data.hx__jianying_triggerable = true
    end
    if data.card.suit == Card.NoSuit then
      room:setPlayerMark(player, "hx__jianying_suit-phase", 0)
    else
      room:setPlayerMark(player, "hx__jianying_suit-phase", data.card:getSuitString())
    end
    room:setPlayerMark(player, "hx__jianying_number-phase", data.card.number)

    room:setPlayerMark(player, "@hx__jianying_record-phase", {data.card:getSuitString(true), data.card:getNumberStr()})
  end,
}


local hx__shibei = fk.CreateTriggerSkill{
  name = "hx__shibei",
  mute = true,
  anim_type = "defensive",
  frequency = Skill.Compulsory,
  events = {fk.Damaged},
  on_use = function(self, event, target, player, data)
    local room = player.room
    if data.isVirtualDMG then return end
    local firstDamage = room.logic:getActualDamageEvents(1, function(e) return e.data[1].to == player end)[1]
    if firstDamage and firstDamage.data[1] == data then
      player:broadcastSkillInvoke(self.name, 1)
      room:notifySkillInvoked(player, self.name)
      if player:isWounded() then
        room:recover{
          who = player,
          num = 1,
          skillName = self.name
        }
      end
    else
      player:broadcastSkillInvoke(self.name, 2)
      room:notifySkillInvoked(player, self.name, "negative")
      room:loseHp(player, 1, self.name)
    end
  end,
}
huixiangqy__nujvshou:addSkill(hx__jianying)
hx__jianying:addRelatedSkill(hx__jianying_trigger)
huixiangqy__nujvshou:addSkill(hx__shibei)
huixiangqy__nujvshou:addSkill(hx__shihuai)


Fk:loadTranslationTable{
  ["huixiangqy__nujvshou"] = "弩沮授",
  ["designer:huixiangqy__nujvshou"] = "非电竞恐龙",
  ["hx__jianying"] = "渐营",
  ["#hx__jianying_trigger"] = "渐营",
  [":hx__jianying"] = "当你于出牌阶段内使用牌时，若此牌与你于此阶段内使用的上一张牌点数或花色相同，你可以摸一张牌。出牌阶段限一次，你可以将一张牌当任意一种基本牌使用，若你于此阶段内使用的上一张牌有花色，则此牌花色视为你本回合使用的上一张牌的花色。",
  ["hx__shibei"] = "矢北",
  [":hx__shibei"] = "锁定技，每当你受到伤害后，若此伤害是你本回合第一次受到的伤害，你回复1点体力；否则你失去1点体力。",
  ["#hx__jianying-active"] = "发动渐营，将一张牌转化为任意基本牌使用",
  ["@hx__jianying_record-phase"] = "渐营",
  ["$hx__jianying1"] = "得胜已是定局，何必急功近利？",
  ["$hx__jianying2"] = "主公坐占胜机，缓行亦无所碍。",
  ["$hx__shibei1"] = "身困敌营，不改向北赤心。",
  ["$hx__shibei2"] = "尽忠竭命，绝不动摇。",
  ["~huixiangqy__nujvshou"] = "只望河北……不受战火侵扰。",
} 

Fk:loadTranslationTable{
  ["hx__kailang"] = "开朗",
  [":hx__kailang"] = "锁定技，你的攻击范围+1，当你使用【杀】对目标角色造成伤害时，若该角色没有手牌，此伤害+1。",
  ["$hx__kailang"] = "古锭刀声~~~",
}
local hx__kailang = fk.CreateTriggerSkill{
  name = "hx__kailang",
  frequency = Skill.Compulsory,
  events = {fk.DamageCaused},
  can_trigger = function(self, _, target, player, data)
    local logic = player.room.logic
    if target == player and player:hasSkill(self) and
    data.to:isKongcheng() and data.card and data.card.trueName == "slash" then
      return data.by_user
    end
  end,
  on_use = function(_, _, _, _, data)
    data.damage = data.damage + 1
  end,
}

local hx__kailang_attackrange = fk.CreateAttackRangeSkill{
  name = "#hx__kailang_attackrange",
  frequency = Skill.Compulsory,
  main_skill = hx__kailang,
  correct_func = function (self, from, to)
    if from:hasSkill(hx__kailang) then
      return 1
    end
    return 0
  end,
}
hx__kailang:addRelatedSkill(hx__kailang_attackrange)

local hx__pojun = fk.CreateTriggerSkill{
  name = "hx__pojun",
  anim_type = "offensive",
  events = {fk.TargetSpecified, fk.DamageCaused},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self) and data.card and data.card.trueName == "slash" then
      if event == fk.TargetSpecified then
        local to = player.room:getPlayerById(data.to)
        return not to.dead and to.hp > 0 and not to:isNude()
      elseif event == fk.DamageCaused then
        return player.room.logic:damageByCardEffect()
        and player:getHandcardNum() >= data.to:getHandcardNum() and
        #player:getCardIds(Player.Equip) >= #data.to:getCardIds(Player.Equip)
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    return event == fk.DamageCaused or player.room:askForSkillInvoke(player, self.name, nil, "#hx__pojun-invoke::"..data.to)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.TargetSpecified then
      room:doIndicate(player.id, {data.to})
      local to = room:getPlayerById(data.to)
      local cards = room:askForCardsChosen(player, to, 1, to.hp, "he", self.name)
      to:addToPile("$hx__pojun", cards, false, self.name)
    else
      data.damage = data.damage + 1
    end
  end,
}

local hx__pojun_delay = fk.CreateTriggerSkill{
  name = "#hx__pojun_delay",
  mute = true,
  events = {fk.TurnEnd},
  can_trigger = function(self, event, target, player, data)
    return #player:getPile("$hx__pojun") > 0
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    player.room:moveCardTo(player:getPile("$hx__pojun"), Player.Hand, player, fk.ReasonPrey, "hx__pojun")
  end,
}

hx__pojun:addRelatedSkill(hx__pojun_delay)
huixiangqy__daoxusheng:addSkill(hx__pojun)
huixiangqy__daoxusheng:addSkill(hx__kailang)

Fk:loadTranslationTable{
  ["hx__pojun"] = "破军",
  ["#hx__pojun_delay"] = "破军",
  [":hx__pojun"] = "①当你使用【杀】指定一个目标后，你可以将其至多X张牌扣置于该角色的武将牌旁（X为其体力值）；若如此做，当前回合结束时，该角色获得这些牌。②当你使用【杀】对手牌数与装备区里的牌数均不大于你的目标角色造成伤害时，此伤害+1。",
  ["#hx__pojun-invoke"] = "是否对%dest发动 破军",
  ["$hx__pojun"] = "破军",
  ["$hx__pojun1"] = "战将临阵，斩关刈城！",
  ["$hx__pojun2"] = "区区数百魏军，看我一击灭之。",
  ["~huixiangqy__daoxusheng"] = "来世……愿再为我江东之臣！",
}

Fk:loadTranslationTable{
  ["hx__sicang"] = "私藏",
  [":hx__sicang"] = "你的攻击范围+2，你可以将两张手牌当普通【杀】使用或打出。",
  ["#hx__sicang"] = "你可以将两张手牌当普通【杀】使用或打出",
  ["$hx__sicang"] = "丈八蛇矛声~~~",
}

local hx__sicang = fk.CreateViewAsSkill{
  name = "hx__sicang",
  prompt = "#hx__sicang",
  pattern = "slash",
  handly_pile = true,
  card_filter = function(self, to_select, selected)
    if #selected == 2 then return false end
    return table.contains(Self:getHandlyIds(true), to_select)
  end,
  view_as = function(self, cards)
    if #cards ~= 2 then
      return nil
    end
    local c = Fk:cloneCard("slash")
    c.skillName = "hx__sicang"
    c:addSubcards(cards)
    return c
  end,
}
local hx__sicang_attackrange = fk.CreateAttackRangeSkill{
  name = "#hx__sicang_attackrange",
  frequency = Skill.Compulsory,
  main_skill = hx__sicang,
  correct_func = function (self, from, to)
    if from:hasSkill(hx__sicang) then
      return 2
    end
    return 0
  end,
}
hx__sicang:addRelatedSkill(hx__sicang_attackrange)

local hx__tushe = fk.CreateTriggerSkill{
  name = "hx__tushe",
  anim_type = "drawcard",
  events = {fk.TargetSpecified},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and data.card.type ~= Card.TypeEquip and data.firstTarget and
      not table.find(player:getCardIds(Player.Hand), function(id) return Fk:getCardById(id).type == Card.TypeBasic end) and
      #AimGroup:getAllTargets(data.tos) > 0
  end,
  on_use = function(self, event, target, player, data)
    player:drawCards(#AimGroup:getAllTargets(data.tos), self.name)
  end,
}
local hx__limu = fk.CreateActiveSkill{
  name = "hx__limu",
  anim_type = "control",
  prompt = "#hx__limu",
  card_num = 1,
  target_num = 0,
  can_use = function(self, player)
    return not player:hasDelayedTrick("indulgence") and not table.contains(player.sealedSlots, Player.JudgeSlot)
  end,
  target_filter = Util.FalseFunc,
  card_filter = function(self, to_select, selected, player)
    if #selected == 0 and Fk:getCardById(to_select).suit == Card.Diamond then
      local card = Fk:cloneCard("indulgence")
      card:addSubcard(to_select)
      return not player:prohibitUse(card) and not player:isProhibited(player, card)
    end
  end,
  on_use = function(self, room, use)
    local player = room:getPlayerById(use.from)
    local cards = use.cards
    local card = Fk:cloneCard("indulgence")
    card:addSubcards(cards)
    room:useCard{
      from = use.from,
      tos = {{use.from}},
      card = card,
    }
    if player:isWounded() and not player.dead then
      room:recover{
        who = player,
        num = 1,
        skillName = self.name
      }
    end
  end,
}
local hx__limu_refresh = fk.CreateTriggerSkill{
  name = "#hx__limu_refresh",
  refresh_events = {fk.PreCardUse},
  can_refresh = function(self, event, target, player, data)
    return player == target and #player:getCardIds(Player.Judge) > 0 and player:hasSkill(hx__limu) and
    table.find(TargetGroup:getRealTargets(data.tos), function (pid)
      return player:inMyAttackRange(player.room:getPlayerById(pid))
    end)
  end,
  on_refresh = function(self, event, target, player, data)
    data.extraUse = true
  end,
}
local hx__limu_targetmod = fk.CreateTargetModSkill{
  name = "#hx__limu_targetmod",
  bypass_times = function(self, player, skill, scope, card, to)
    return card and player:hasSkill(hx__limu) and #player:getCardIds(Player.Judge) > 0 and to and player:inMyAttackRange(to)
  end,
  bypass_distances =  function(self, player, skill, card, to)
    return card and player:hasSkill(hx__limu) and #player:getCardIds(Player.Judge) > 0 and to and player:inMyAttackRange(to)
  end,
}
hx__limu:addRelatedSkill(hx__limu_refresh)
hx__limu:addRelatedSkill(hx__limu_targetmod)
huixiangqy__maoliuyan:addSkill(hx__tushe)
huixiangqy__maoliuyan:addSkill(hx__limu)
huixiangqy__maoliuyan:addSkill(hx__sicang)

Fk:loadTranslationTable{
  ["hx__tushe"] = "图射",
  [":hx__tushe"] = "当你使用非装备牌指定目标后，若你没有基本牌，则你可以摸X张牌（X为此牌指定的目标数）。",
  ["hx__limu"] = "立牧",
  [":hx__limu"] = "出牌阶段，你可以将一张方块牌当【乐不思蜀】对自己使用，然后回复1点体力；你的判定区有牌时，你对攻击范围内的其他角色使用牌没有次数和距离限制。",
  ["#hx__limu"] = "立牧：选择一张方块牌当【乐不思蜀】对自己使用，然后回复1点体力",
  ["$hx__tushe1"] = "图谋霸业，此为长远之法！",
  ["$hx__tushe2"] = "为护子孙，才会有所图谋！",
  ["$hx__limu1"] = "这益州牧，我可是当定了！",
  ["$hx__limu2"] = "宗亲立牧，顺应天时！",
  ["~huixiangqy__maoliuyan"] = "我怎会有，图谋不轨之心……",
}

local hx__shanjia = fk.CreateTriggerSkill{
  name = "hx__shanjia",
  anim_type = "drawcard",
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player.phase == Player.Play
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:drawCards(player, 3, self.name)
    if player.dead then return false end
    U.askForUseVirtualCard(room, player, "slash", {}, self.name, "#hx__shanjia-slash", true, true, false, true)
  end,
}
huixiangqy__xingcaochun:addSkill(hx__shanjia)
Fk:loadTranslationTable{
  ["hx__shanjia"] = "缮甲",
  [":hx__shanjia"] = "出牌阶段开始时，你可以摸三张牌，并视为使用一张不计入次数的普通【杀】。",
  ["#hx__shanjia-slash"] = "缮甲：你可以视为对一名角色使用一张不计入次数的普通【杀】",
  ["$hx__shanjia1"] = "若非磨牙利爪，安可得虎豹之师？",
  ["$hx__shanjia2"] = "虎豹骁锐，定当所向披靡！",
  ["~huixiangqy__xingcaochun"] = "虎豹军魂，谁……可续之……",
  ["$huixiangqy__xingcaochun_win_audio"] = "哼，我虎豹之师岂是尔等能抵挡的？",
}
local huixiangqy__xingcaochunwin = fk.CreateActiveSkill{ name = "huixiangqy__xingcaochun_win_audio" }
huixiangqy__xingcaochunwin.package = extension
Fk:addSkill(huixiangqy__xingcaochunwin)

Fk:loadTranslationTable{
  ["~huixiangqy__hewenyang"] = "洛阳宫前屈枉冢，乐嘉城上凄然风……",
  ["$huixiangqy__hewenyang_win_audio"] = "秦凉既平，吾定名震天下！",
}
local huixiangqy__hewenyangwin = fk.CreateActiveSkill{ name = "huixiangqy__hewenyang_win_audio" }
huixiangqy__hewenyangwin.package = extension
Fk:addSkill(huixiangqy__hewenyangwin)

local hx__quedi = fk.CreateTriggerSkill{
  name = "hx__quedi",
  anim_type = "offensive",
  events = {fk.TargetSpecified},
  can_trigger = function(self, event, target, player, data)
    return
      target == player and
      player:hasSkill(self) and
      player:usedSkillTimes(self.name, Player.HistoryTurn) < (1 + player:getMark("hx__choujue_buff-turn")) and
      table.contains({ "slash", "duel" }, data.card.trueName) and
      AimGroup:isOnlyTarget(player.room:getPlayerById(data.to), data) and
      player.room:getPlayerById(data.to):isAlive()
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local choices = {"beishui", "hx__quedi-offense","Cancel"}
    local to = room:getPlayerById(data.to)
    if not to:isKongcheng() then
      table.insert(choices, "hx__quedi-prey")
    end
    local prompt = "#hx__quedi-choice::"..data.to..":"..player:usedSkillTimes(self.name, Player.HistoryTurn)..":"
    ..(1 + player:getMark("hx__choujue_buff-turn"))
    local choice = room:askForChoice(player, choices, self.name, prompt, nil,
    {"beishui", "hx__quedi-prey", "hx__quedi-offense", "Cancel"})
    if choice ~= "Cancel" then
      self.cost_data = choice
      return true
    end
    return false
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(data.to)
    if self.cost_data == "hx__quedi-prey" or (self.cost_data == "beishui" and not to:isKongcheng()) then
      local cardId = room:askForCardChosen(player, to, "h", self.name)
      room:obtainCard(player, cardId, false, fk.ReasonPrey)
      if player.dead then return false end
    end
    if self.cost_data == "hx__quedi-offense" or self.cost_data == "beishui" then
      if #room:askForDiscard(player, 1, 1, false, self.name, true, ".|.|.|.|.|basic",
        "#hx__quedi-discard:::" .. data.card.trueName) > 0 then
        data.additionalDamage = (data.additionalDamage or 0) + 1
        if player.dead then return false end
      end
    end
    if self.cost_data == "beishui" then
      room:changeMaxHp(player, -1)
    end
  end,
}
Fk:loadTranslationTable{
  ["hx__quedi"] = "却敌",
  [":hx__quedi"] = "每回合限一次，当你使用【杀】或【决斗】指定唯一目标后，你可以选择一项：1.获得其一张手牌；2.弃置一张基本牌，令此【杀】或【决斗】"..
  "伤害基数+1；背水：减1点体力上限。",
  ["hx__quedi-prey"] = "获得其手牌",
  ["hx__quedi-offense"] = "弃基本牌令此伤害+1",
  ["#hx__quedi-discard"] = "却敌：可以弃置1张基本牌，令此【%arg】伤害+1",
  ["#hx__quedi-choice"] = "你可以对 %dest 发动“却敌”（已用：%arg/%arg2）",
  ["$hx__quedi1"] = "乐嘉风起残云散，万钧雷震万千军！",
  ["$hx__quedi2"] = "进袭如惊涛，破围如落潮！",
}

huixiangqy__hewenyang:addSkill(hx__quedi)

local hx__chuifeng = fk.CreateViewAsSkill{
  name = "hx__chuifeng",
  anim_type = "offensive",
  times = function(self)
    return Self.phase == Player.Play and 2 - Self:usedSkillTimes(self.name, Player.HistoryPhase) or -1
  end,
  prompt = function (self)
    return "#hx__chuifeng-prompt:::"..Self:usedSkillTimes(self.name, Player.HistoryPhase)
  end,
  enabled_at_play = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) < 2 and player.hp > 0
  end,
  card_filter = Util.FalseFunc,
  view_as = function(self, cards)
    local card = Fk:cloneCard("duel")
    card.skillName = self.name
    return card
  end,
  before_use = function(self, player)
    player.room:loseHp(player, 1, self.name)
  end
}
local hx__chuifengDefence = fk.CreateTriggerSkill{
  name = "#hx__chuifeng_defence",
  anim_type = "defensive",
  events = {fk.DamageInflicted},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(hx__chuifeng) and data.card and table.contains(data.card.skillNames, hx__chuifeng.name)
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    player.room:invalidateSkill(player, "hx__chuifeng", "-phase")
    return true
  end,
}

hx__chuifeng:addRelatedSkill(hx__chuifengDefence)
Fk:loadTranslationTable{
  ["hx__chuifeng"] = "椎锋",
  ["#hx__chuifeng_defence"] = "椎锋",
  [":hx__chuifeng"] = "出牌阶段限两次，你可以失去1点体力，并视为使用一张【决斗】。"..
  "当你受到以此法使用的【决斗】造成的伤害时，防止此伤害，此技能于此阶段内无效。",
  ["#hx__chuifeng-prompt"] = "椎锋：失去1点体力，并视为使用一张【决斗】（已用：%arg/2）",
  ["$hx__chuifeng1"] = "淮南讨逆之役，次骞愿为先锋！",
  ["$hx__chuifeng2"] = "吾枪之利？汝一试便知！",
}

huixiangqy__hewenyang:addSkill(hx__chuifeng)

local hx__chongjian = fk.CreateViewAsSkill{
  name = "hx__chongjian",
  prompt = "#hx__chongjian-prompt",
  interaction = function()
    local names = {}
    for name, _ in pairs(Fk.all_card_types) do
      local card = Fk:cloneCard(name)
      if not card.is_derived and not table.contains(Fk:currentRoom().disabled_packs, card.package.name)
        and (card.name == "analeptic" or card.trueName == "slash")
        and ((Fk.currentResponsePattern == nil and Self:canUse(card)) or
        (Fk.currentResponsePattern and Exppattern:Parse(Fk.currentResponsePattern):match(card))) then
        table.insertIfNeed(names, name)
      end
    end
    if #names == 0 then return end
    return UI.ComboBox {choices = names}
  end,
  pattern = "slash,analeptic",
  handly_pile = true,
  card_filter = function(self, to_select, selected)
    return #selected == 0 and Fk:getCardById(to_select).type == Card.TypeEquip
  end,
  view_as = function(self, cards)
    if #cards ~= 1 or not self.interaction.data then return end
    local card = Fk:cloneCard(self.interaction.data)
    card:addSubcard(cards[1])
    card.skillName = self.name
    return card
  end,
  before_use = function(self, player, useData)
    useData.extra_data = useData.extra_data or {}
    useData.extra_data.chongjianUser = player.id
  end,
  enabled_at_response = function(self, player, cardResponsing)
    return player:hasSkill(self) and not cardResponsing
  end,
}
Fk:loadTranslationTable{
  ["hx__chongjian"] = "冲坚",
  [":hx__chongjian"] = "你可以将一张装备牌当【酒】或无距离限制且无视防具的任意一种【杀】使用。当你以此法使用的【杀】对一名角色造成伤害后，"..
  "你获得其装备区里的X张牌（X为伤害值）。",
  ["#hx__chongjian_buff"] = "冲坚",
  ["#hx__chongjian-prompt"] = "冲坚：将装备牌当【酒】或无距离限制且无视防具的任意一种【杀】使用",
  ["$hx__chongjian1"] = "奋六钧之力，破九天重云！",
  ["$hx__chongjian2"] = "攻敌营垒，不留一隅之地！",
}

local hx__chongjianBuff = fk.CreateTriggerSkill{
  name = "#hx__chongjian_buff",
  mute = true,
  events = {fk.Damage},
  can_trigger = function (self, event, target, player, data)
    if not (player.dead or data.to.dead) and #data.to:getCardIds(Player.Equip) > 0 then
      local parentUseData = player.room.logic:getCurrentEvent():findParent(GameEvent.UseCard)
      return parentUseData and (parentUseData.data[1].extra_data or {}).chongjianUser == player.id
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local equipsNum = #data.to:getCardIds(Player.Equip)
    local num = math.min(equipsNum, data.damage)
    local cards = room:askForCardsChosen(player, data.to, num, num, "e", self.name)
    room:obtainCard(player, cards, true, fk.ReasonPrey, player.id, self.name)
  end,
  refresh_events = { fk.TargetSpecified },
  can_refresh = function (self, event, target, player, data)
    return not player.dead and (data.extra_data or {}).chongjianUser == player.id
  end,
  on_refresh = function (self, event, target, player, data)
    local to = player.room:getPlayerById(data.to)
    if not to.dead then
      to:addQinggangTag(data)
    end
  end
}

hx__chongjian:addRelatedSkill(hx__chongjianBuff)

local hx__chongjianUnlimited = fk.CreateTargetModSkill{
  name = "#hx__chongjian_unlimited",
  bypass_distances = function(self, player, skill, card)
    return card and table.contains(card.skillNames, hx__chongjian.name)
  end,
}

hx__chongjian:addRelatedSkill(hx__chongjianUnlimited)
huixiangqy__hewenyang:addSkill(hx__chongjian)

local hx__choujue = fk.CreateTriggerSkill{
  name = "hx__choujue",
  anim_type = "drawcard",
  events = {fk.Deathed},
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and data.damage and data.damage.from == player
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:changeMaxHp(player, 1)
    if player.dead then return false end
    room:drawCards(player, 2, self.name)
    room:addPlayerMark(player, "hx__choujue_buff-turn", 1)
  end,
}
Fk:loadTranslationTable{
  ["hx__choujue"] = "仇决",
  [":hx__choujue"] = "锁定技，当你杀死一名角色后，你加1点体力上限，摸两张牌，你本回合〖却敌〗可发动次数+1。",
  ["$hx__choujue1"] = "国仇家怨，汝搓骨难偿！",
  ["$hx__choujue2"] = "彻天盈海之仇，纵身死亦不绝！",
}

huixiangqy__hewenyang:addSkill(hx__choujue)

local hx__fuji = fk.CreateTriggerSkill{
  name = "hx__fuji",
  anim_type = "offensive",
  events = {fk.CardUsing},
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and
      (data.card.trueName == "slash" or data.card:isCommonTrick()) and
      table.find(player.room:getOtherPlayers(player), function(p) return p:distanceTo(player) < 3 or player:inMyAttackRange(p) end)
  end,
  on_use = function(self, event, target, player, data)
    local targets = table.filter(player.room:getOtherPlayers(player), function(p) return p:distanceTo(player) <3 or player:inMyAttackRange(p) end)
    if #targets > 0 then
      data.disresponsiveList = data.disresponsiveList or {}
      for _, p in ipairs(targets) do
        table.insertIfNeed(data.disresponsiveList, p.id)
      end
    end
  end,
}
local hx__fuji_attack = fk.CreateTriggerSkill{
  name = "#hx__fuji_attack",
  anim_type = "offensive",
  mute = true,
  events = {fk.Damaged},
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
      return target ~= player and data.from == player and player:hasSkill(self)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
      room:addPlayerMark(target, "@@hx__fuji")
      room:addPlayerMark(target, MarkEnum.UncompulsoryInvalidity)
  end,
  refresh_events = { fk.TurnEnd },
  can_refresh = function(self, event, target, player, data)
      return true 
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    for _, p in ipairs(room:getAlivePlayers()) do
      if p:getMark("@@hx__fuji") > 0 then
        room:removePlayerMark(p, "@@hx__fuji")
        room:removePlayerMark(p,MarkEnum.UncompulsoryInvalidity)
      end
    end
  end,
}
local hx__jiaozi = fk.CreateTriggerSkill{
  name = "hx__jiaozi",
  anim_type = "offensive",
  events = {fk.DamageCaused},
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and
      table.every(player.room:getOtherPlayers(player), function(p)
        return player:getHandcardNum() >= p:getHandcardNum() end)
  end,
  on_use = function(self, event, target, player, data)
    data.damage = data.damage + 1
  end,
}
hx__fuji:addRelatedSkill(hx__fuji_attack)
huixiangqy__jiequyi:addSkill(hx__fuji)
huixiangqy__jiequyi:addSkill(hx__jiaozi)

Fk:loadTranslationTable{
  ["hx__fuji"] = "伏骑",
  ["#hx__fuji_attack"] = "伏骑",
  [":hx__fuji"] = "锁定技，当你使用【杀】或普通锦囊牌时，你令在你攻击范围内所有与你距离为2的其他角色不能响应此牌，且被你造成伤害的其他角色的非锁定技失效直到一个回合结束。",
  ["hx__jiaozi"] = "骄恣",
  [":hx__jiaozi"] = "锁定技，当你造成伤害时，若你的手牌为全场最多，则此伤害+1。",
  ["@@hx__fuji"] = "伏骑",
  ["$hx__fuji1"] = "举足覆手之间，白马尽作烟灭！",
  ["$hx__fuji2"] = "纵骑轻进？哼！且试吾强弩之威！",
  ["$hx__jiaozi1"] = "此番快战，义必三胜而归！",
  ["$hx__jiaozi2"] = "先拔牙门纛，再立夺胜功！",
  ["~huixiangqy__jiequyi"] = "主公能容天下之士，为何独不容我……",
  ["$huixiangqy__jiequyi_win_audio"] = "主公胜局，经此一役可定！",
}
local huixiangqy__jiequyiwin = fk.CreateActiveSkill{ name = "huixiangqy__jiequyi_win_audio" }
huixiangqy__jiequyiwin.package = extension
Fk:addSkill(huixiangqy__jiequyiwin)



Fk:loadTranslationTable{
  ["huixiangqy__shisunquan"] = "势孙权",
  ["designer:huixiangqy__shisunquan"] = "北月畫仙",
  ["hx__zhiheng_shi"] = "制衡",
  ["#hx__zhiheng_shi_count"] = "制衡",
  [":hx__zhiheng_shi"] = "锁定技，转换技，阳：你使用或打出一张手牌时，摸两张牌。阴：你使用或打出共计两张手牌时，弃置一至两张牌，每当你于出牌阶段内触发两次此技能效果时，你本回合“昭威”发动次数+1。",
  ["hx__zhaowei_shi"] = "昭威",
  [":hx__zhaowei_shi"] = "转换技，出牌阶段限一次，阳：你展示自己的全部手牌，如果其中黑色牌的数量等于红色牌的数量，你可以依次摸两张指定类型的牌；阴：你展示自己的全部手牌，如果其中基本牌的数量等于非基本牌，你可以弃置两张牌并视为使用任意一张基本牌或普通锦囊牌（每轮每种牌名限一次且无次数和距离限制）。",
  ["$hx__zhiheng_shi1"] = "不急，吾等必一击制敌。",
  ["$hx__zhiheng_shi2"] = "纵横捭阖，自有制衡之道。",
  ["$hx__zhaowei_shi1"] = "据长江之险，用贤德之才，吾，岂会落败！",
  ["$hx__zhaowei_shi2"] = "吴侯终为人臣，岂比一国之君！",
  ["~huixiangqy__shisunquan"] = "父兄大计，权，实憾矣。",
  ["@hx__zhiheng_shi_reset"] = "制衡次数",
  ["#hx__zhaowei_shi-yang"] = "你展示自己的全部手牌，如果其中黑色牌的数量等于红色牌的数量，你可以依次摸两张指定类型的牌",
  ["#hx__zhaowei_shi-yin"] = "你展示自己的全部手牌，如果其中基本牌的数量等于非基本牌，你可以弃置两张牌并视为使用任意一张基本牌或普通锦囊牌（每轮每种牌名限一次且无次数和距离限制）",
  ["#hx__zhaowei_shi-ask"] = "昭威：请选择要使用的基本牌或普通锦囊牌",
  ["#hx__zhaowei_shi-target"] = "请选择此牌目标",
  ["@$hx__zhaowei_shi-round"] = "昭威已使用",
  ["@hx__zhaowei_shi_skill-turn"] = "昭威次数+",
} 

local hx__zhiheng_shi = fk.CreateTriggerSkill{
  name = "hx__zhiheng_shi",
  switch_skill_name = "hx__zhiheng_shi",
  frequency = Skill.Compulsory,
  events = {fk.CardUsing,fk.CardResponding},
  can_trigger = function(self, event, target, player, data)
    if player:getSwitchSkillState(self.name, false) == fk.SwitchYang then
      return U.IsUsingHandcard(player, data) and player:hasSkill(self) and target == player
    elseif player:getSwitchSkillState(self.name, false) == fk.SwitchYin and player:getMark("hx__zhiheng_shi_count") > 1 then
      return U.IsUsingHandcard(player, data) and player:hasSkill(self) and target == player 
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if player.phase == Player.Play then
      room:addPlayerMark(player, "@hx__zhiheng_shi_reset", 1)
      if player:getMark("@hx__zhiheng_shi_reset") > 1 then
        room:setPlayerMark(player, "@hx__zhiheng_shi_reset", 0)
        room:addPlayerMark(player, "@hx__zhaowei_shi_skill-turn", 1)
      end
    end
    if player:getSwitchSkillState(self.name, true) == fk.SwitchYang then
      room:addPlayerMark(player, "hx__zhiheng_shi_yang", 1)
      player:drawCards(2, self.name)
    else
      room:setPlayerMark(player, "hx__zhiheng_shi_count", 0)
      room:setPlayerMark(player, "hx__zhiheng_shi_yang", 0)
      if #player:getCardIds{Player.Hand, Player.Equip} == 0 then return end
      room:askForDiscard(player, 1, 2, true, self.name, false,".","请弃置一至两张牌")
    end
  end,
}

local hx__zhiheng_shi_count = fk.CreateTriggerSkill{
  name = "#hx__zhiheng_shi_count",
  priority = 0.1,
  mute = true,
  frequency = Skill.Compulsory,
  events = {fk.CardUsing,fk.CardResponding},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player:getMark("hx__zhiheng_shi_yang") > 0 and U.IsUsingHandcard(player, data)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:addPlayerMark(player, "hx__zhiheng_shi_count", 1)
  end,
}


local hx__zhaowei_shi = fk.CreateActiveSkill{
  name = "hx__zhaowei_shi",
  anim_type = "switch",
  switch_skill_name = "hx__zhaowei_shi",
  target_num = 0,
  prompt = function(self, selected, selected_cards)
		if Self:getSwitchSkillState(self.name, false) == fk.SwitchYang then
      return "#hx__zhaowei_shi-yang"
    else
      return "#hx__zhaowei_shi-yin"
    end
  end,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) < 1 + player:getMark("@hx__zhaowei_shi_skill-turn") and player:getHandcardNum() > 0
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local cards = player.player_cards[Player.Hand]
    player:showCards(cards)
    if player:getSwitchSkillState(self.name, true) == fk.SwitchYang then
      if #table.filter(cards, function(id) return Fk:getCardById(id).color == Card.Black end) 
        == #table.filter(cards, function(id) return Fk:getCardById(id).color == Card.Red end) then
        local choice11 = room:askForChoice(player, {"hx__taohui_b","hx__taohui_t","hx__taohui_e","Cancel"},self.name,"请选择第一张要摸的牌的类型")
        if choice11 == "hx__taohui_b" then
          local cards = player.room:getCardsFromPileByRule(".|.|.|.|.|basic")
          if #cards > 0 then
            room:obtainCard(player, cards[1], false, fk.ReasonDraw, player.id, self.name)
          end
        elseif choice11 == "hx__taohui_t" then
          local cards = player.room:getCardsFromPileByRule(".|.|.|.|.|trick")
          if #cards > 0 then
            room:obtainCard(player, cards[1], false, fk.ReasonDraw, player.id, self.name)
          end
        elseif choice11 == "hx__taohui_e" then
          local cards = player.room:getCardsFromPileByRule(".|.|.|.|.|equip")
          if #cards > 0 then
            room:obtainCard(player, cards[1], false, fk.ReasonDraw, player.id, self.name)
          end
        end
        local choice11 = room:askForChoice(player, {"hx__taohui_b","hx__taohui_t","hx__taohui_e","Cancel"},self.name,"请选择第二张要摸的牌的类型")
        if choice11 == "hx__taohui_b" then
          local cards = player.room:getCardsFromPileByRule(".|.|.|.|.|basic")
          if #cards > 0 then
            room:obtainCard(player, cards[1], false, fk.ReasonDraw, player.id, self.name)
          end
        elseif choice11 == "hx__taohui_t" then
          local cards = player.room:getCardsFromPileByRule(".|.|.|.|.|trick")
          if #cards > 0 then
            room:obtainCard(player, cards[1], false, fk.ReasonDraw, player.id, self.name)
          end
        elseif choice11 == "hx__taohui_e" then
          local cards = player.room:getCardsFromPileByRule(".|.|.|.|.|equip")
          if #cards > 0 then
            room:obtainCard(player, cards[1], false, fk.ReasonDraw, player.id, self.name)
          end
        end
      end
    else
      if #table.filter(cards, function(id) return Fk:getCardById(id).type == Card.TypeBasic end) 
        == #table.filter(cards, function(id) return Fk:getCardById(id).type ~= Card.TypeBasic end) then
        local discards = room:askForDiscard(player, 2, 2, true, self.name, true,".","你可以弃置两张牌并视为使用任意一张基本牌或普通锦囊牌（无次数和距离限制）",true)
        if #discards > 0 then
          room:throwCard(discards,self.name,player,player)
          local mark = player:getMark("hx__zhaowei_shi_names")
          if type(mark) ~= "table" then
            mark = U.getAllCardNames("bt")
            room:setPlayerMark(player, "hx__zhaowei_shi_names", mark)
            end
            local used = player:getTableMark("@$hx__zhaowei_shi-round")
            local all_names, names = {}, {}
            for _, name in ipairs(mark) do
              local card = Fk:cloneCard(name)
              card.skillName = self.name
              if not player:prohibitUse(card) then
                table.insert(all_names, name)
                if not table.contains(used, name) then
                  table.insert(names, name)
                end
              end
            end
            local choices = U.askForChooseCardNames(room, player, names, 1, 1, self.name, "#hx__zhaowei_shi-ask", all_names)
            room:addTableMark(player, "@$hx__zhaowei_shi-round", choices[1])
            U.askForUseVirtualCard(room, player, choices[1], nil, self.name, "#hx__zhaowei_shi-target",false, true, true)
          end
        end
    end 
  end,
}

huixiangqy__shisunquan:addSkill(hx__zhiheng_shi)
hx__zhiheng_shi:addRelatedSkill(hx__zhiheng_shi_count)
huixiangqy__shisunquan:addSkill(hx__zhaowei_shi)


Fk:loadTranslationTable{
  ["hx__sihai"] = "四害",
  [":hx__sihai"] = "锁定技，游戏开始时，你获得4个“四害”标记。准备阶段开始时，你消耗1个“四害”标记并选择一名其他角色你们共同执行以一种效果："..
  "<br>苍蝇：你与你所选择的角色失去技能一轮。"..
  "<br>蚊子：你与你所选择的角色处于翻面状态一轮。"..
  "<br>老鼠：你与你所选择的角色废除所有装备栏一轮。"..
  "<br>蟑螂：你与你所选择的角色不能使用或打出手牌一轮。",
  ["hx__sanyin"] = "三阴",
  [":hx__sanyin"] = "当一名角色死亡时，你可以令一名角色选择一项：1.回复一点体力；2.摸两张牌。",
  ["@@cangying"] = "苍蝇",
  ["@@wenzi"] = "蚊子",
  ["@@laoshu"] = "老鼠",
  ["@@zhanglang"] = "蟑螂",
  ["@@cangying-tos"] = "失去技能一轮",
  ["@@laoshu-tos"] = "废除所有装备栏一轮",
  ["@@cangying-player"] = "失去技能一轮",
  ["@@zhanglang-round"] = "禁出手牌一轮",
  ["$hx__sihai"] = "尔等为祸乡里，当知有此一劫!",
  ["$hx__sanyin"] = "既悔前事之祸，今唯律己改之!",
  ["~huixiangqy__bianzhouchu"] = "只愿今日之行，可偿昔日之孽……",
}

local hx__sihai = fk.CreateTriggerSkill{
  name = "hx__sihai",
  anim_type = "offensive",
  frequency = Skill.Compulsory,
  events = {fk.GameStart, fk.EventPhaseStart, fk.RoundEnd},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) then
      if event == fk.GameStart then
        return true
      elseif event == fk.EventPhaseStart then
        return target == player and player.phase == Player.Start and 
        (player:getMark("@@cangying") > 0 or player:getMark("@@wenzi") > 0 or player:getMark("@@laoshu") > 0 or player:getMark("@@zhanglang") > 0)
      elseif event == fk.RoundEnd then
        return player:getMark("@@laoshu") == 0 and player:getMark("laoshu") == 0
      end
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local subtype = {Card.SubtypeWeapon, Card.SubtypeArmor, Card.SubtypeOffensiveRide, Card.SubtypeDefensiveRide, Card.SubtypeTreasure}
    if event == fk.GameStart then
      room:addPlayerMark(player, "@@cangying")
      room:addPlayerMark(player, "@@wenzi")
      room:addPlayerMark(player, "@@laoshu")
      room:addPlayerMark(player, "@@zhanglang")
    elseif event == fk.EventPhaseStart and player.phase == Player.Start then
      local choice = {}
      if player:getMark("@@cangying") > 0 then
       table.insert(choice, "苍蝇：你与你所选择的角色失去技能一轮")
      end
      if player:getMark("@@wenzi") > 0 then
        table.insert(choice, "蚊子：你与你所选择的角色处于翻面状态一轮")
      end
      if player:getMark("@@laoshu") > 0 then
        table.insert(choice, "老鼠：你与你所选择的角色废除所有装备栏一轮")
      end
      if player:getMark("@@zhanglang") > 0 then
        table.insert(choice, "蟑螂：你与你所选择的角色不能使用或打出手牌一轮")
      end
      if #choice == 0 then return end
      local choose = room:askForChoice(player, choice, self.name, "请选择要消耗标记")
      if #choose == 0 then return end
      local to = room:askForChoosePlayers(player, table.map(room:getOtherPlayers(player,false), Util.IdMapper), 1, 1, "请选择一名与你共同执行该标记效果的其他角色", self.name, false)
      if #to == 0 then return end
      local tos = room:getPlayerById(to[1])
      if choose == "苍蝇：你与你所选择的角色失去技能一轮" then
        room:removePlayerMark(player, "@@cangying")
        room:addPlayerMark(player, "cangying", 1)
        local skills = table.map(table.filter(player.player_skills, function(skill)
          return skill:isPlayerSkill(player)
        end), function(s)
          return s.name
        end)
        room:setTag("cangying1", skills)
        local skills2 = table.map(table.filter(tos.player_skills, function(skill)
          return skill:isPlayerSkill(tos)
        end), function(s)
          return s.name
        end)
        room:setTag("cangying2", skills2)
        room:addPlayerMark(tos, "@@cangying-tos")
        room:addPlayerMark(player, "@@cangying-player")
        room:handleAddLoseSkills(tos, "-"..table.concat(skills2, "|-"), nil, true, false)
        room:handleAddLoseSkills(player, "-"..table.concat(skills, "|-"), nil, true, false)

      elseif choose == "蚊子：你与你所选择的角色处于翻面状态一轮" then
        room:removePlayerMark(player, "@@wenzi")
        tos:turnOver()
        player:turnOver()
      elseif choose == "老鼠：你与你所选择的角色废除所有装备栏一轮" then
        room:removePlayerMark(player, "@@laoshu")
        local slots = {}
        for _, type in ipairs(subtype) do
          for i = 1, #player:getAvailableEquipSlots(type), 1 do
            table.insert(slots, Util.convertSubtypeAndEquipSlot(type))
          end
        end
        if not player.dead then
          room:abortPlayerArea(player, slots)
          room:addPlayerMark(player, "@@laoshu-tos")
        end
        if not tos.dead then
          room:abortPlayerArea(tos, slots)
          room:addPlayerMark(tos, "@@laoshu-tos")
        end
      elseif choose == "蟑螂：你与你所选择的角色不能使用或打出手牌一轮" then
        room:removePlayerMark(player, "@@zhanglang")
        room:addPlayerMark(player, "@@zhanglang-round")
        room:addPlayerMark(tos, "@@zhanglang-round")
      end
    elseif event == fk.RoundEnd then
      if player:getMark("@@laoshu") == 0 then
        room:addPlayerMark(player, "laoshu", 1)
        local slots = table.simpleClone(player.sealedSlots)
        if not player.dead then
          room:resumePlayerArea(player, slots)
          room:removePlayerMark(player, "@@laoshu-tos")
        end
        local tos = table.filter(room:getAlivePlayers(), function(p) return p:getMark("@@laoshu-tos") > 0 and p.id ~= player.id end)
        if #tos == 0 then return end
        local to = tos[1]
        local slots2 = table.simpleClone(to.sealedSlots)
        room:resumePlayerArea(to, slots2)
        room:removePlayerMark(to, "@@laoshu-tos")
      end
    end
  end,
}

local hx__sihai_prohibit = fk.CreateProhibitSkill{
  name = "#hx__sihai_prohibit",
  prohibit_use = function(self, player, card)
    if player:getMark("@@zhanglang-round") == 0 then return false end
    local subcards = Card:getIdList(card)
    return #subcards > 0 and table.every(subcards, function(id)
      return table.contains(player:getCardIds(Player.Hand), id)
    end)
  end,
  prohibit_response = function(self, player, card)
    if player:getMark("@@zhanglang-round") == 0 then return false end
    local subcards = Card:getIdList(card)
    return #subcards > 0 and table.every(subcards, function(id)
      return table.contains(player:getCardIds(Player.Hand), id)
    end)
  end,
}

local hx__sihai_recover = fk.CreateTriggerSkill{
  name = "hx__sihai_recover",
  mute = true,
  global = true,
  priority = 0.1,
  frequency = Skill.Compulsory,
  events = {fk.RoundEnd},
  can_trigger = function(self, event, target, player, data)
    return #table.filter(player.room:getAlivePlayers(), function(p) return p:getMark("@@cangying-player") > 0 end) > 0
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local tos2 = table.filter(room:getAlivePlayers(), function(p) return p:getMark("@@cangying-player") > 0 end)
    local skills = {room:getTag("cangying1")} or {}
    if #tos2 > 0 then
      room:removePlayerMark(tos2[1], "cangying")
      for _, skill_name in ipairs(skills) do
        room:handleAddLoseSkills(tos2[1], skill_name, nil, false, true)
      end
      room:removePlayerMark(tos2[1], "@@cangying-player")
    end
    local tos1 = table.filter(room:getAlivePlayers(), function(p) return p:getMark("@@cangying-tos") > 0 end)
    if #tos1 == 0 then return end
    if #tos1 > 0 then
      local skills2 = {room:getTag("cangying2")} or {}
      for _, skill_name in ipairs(skills2) do
        room:handleAddLoseSkills(tos1[1], skill_name, nil, false, true)
      end
      room:removePlayerMark(tos1[1], "@@cangying-tos")
    end
  end,
}

Fk:addSkill(hx__sihai_recover)

local hx__sanyin = fk.CreateTriggerSkill{
  name = "hx__sanyin",
  anim_type = "control",
  events = {fk.Death}, 
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local tos = room:askForChoosePlayers(player, table.map(room:getAlivePlayers(), Util.IdMapper), 1, 1, "请选择一名执行选项的角色", self.name)
    local to = room:getPlayerById(tos[1])
    local choice = room:askForChoice(to, {"回复一点体力","摸两张牌"}, self.name, "请选择一项")
    if choice == "回复一点体力" then
      room:recover({
        who = to,
        num = 1,
        skillName = self.name
      })
    elseif choice == "摸两张牌" then
      to:drawCards(2, self.name)
    end
  end,
}

huixiangqy__bianzhouchu:addSkill(hx__sihai)
hx__sihai:addRelatedSkill(hx__sihai_prohibit)
huixiangqy__bianzhouchu:addSkill(hx__sanyin)



return extension